示例#1
0
function makeChapter($startpoint,$startlat,$startlon,$direction=-1)
{
	global $roomsleft,$done,$localguide,$localguidehome,$traveller,$leap,$laststation,$weatherlist,$weather,$lastspeaker,$lastprintedlat,
		   $lastprintedlon,$opening,$paragraphnumber,$passedplace;
	
	$lastspeaker = "";
	$ourgroup = "$traveller and I";
	if ($localguide != "")
	{ $ourgroup = "$traveller, $localguide and I"; }
	
	$dx=$lastprintedlat-$startlat;
	$dy=$lastprintedlon-$startlon;
	$distance = sqrt($dx*$dx+$dy*$dy);
	$minuteswalked = $distance*2000;
	if ($minuteswalked>=240) // time for a new chapter
	{ $paragraphnumber = 1; }
				
	$chapter = "";
	if ($paragraphnumber == 1)	
	{ $chapter .= "<p class=\"new\">"; }
	else
	{ $chapter .= "<p>&nbsp;&nbsp;"; }
	
	list($original,$article) = fetchArticle($startpoint);

	$cleanstartpoint = preg_replace("/[^A-Za-z 0-9,']/","",$startpoint);
	
 	$speaker = $traveller;
	if (rand(1,2)==1 && $localguide <> "") { $speaker = $localguide; }
	  
	if ($opening==1)
	{
		$chapter .= "Setting out from $passedplace, we headed for ".$startpoint.". ";
	}
	elseif (preg_match("/'''".$cleanstartpoint."''' was/",$original,$matches))
	{
		switch (rand(1,4)) {
			case 1; $chapter .= "We passed the site of ".$startpoint.". "; break;
			case 2; $chapter .= "Near here was the site of ".$startpoint.". "; break;
			case 3; $chapter .= "I remembered ".$startpoint.". "; break;
			case 4; $chapter .= "$speaker told me about ".$startpoint.". "; break;
		}
	}
	elseif (preg_match("/HMS/",$startpoint,$matches))
	{
		switch (rand(1,4)) {
			case 1; $chapter .= "We drifted past ".$startpoint.". "; break;
			case 2; $chapter .= "We passed ".$startpoint.". "; break;
			case 3; $chapter .= "Through the fog we saw ".$startpoint.". "; break;
			case 4; $chapter .= "$speaker pointed out ".$startpoint.". "; break;
		}
	}
	elseif (preg_match("/^List of (.+)$/",$startpoint,$matches)) // some list articles have geotags, it turns out
	{
		switch (rand(1,4)) {
			case 1; $chapter .= "While we travelled, I ".randString("perused","skimmed","read")." a list of ".$startpoint.". "; break;
			case 2; $chapter .= "My guidebook provided a list of ".$startpoint.". "; break;
			case 3; $chapter .= "Unexpectedly, $traveller began to ".randString("reel","read")." out a list of ".$startpoint.". "; break;
			case 4; $chapter .= "I ".randString("perused","skimmed","read")." a list of ".$startpoint.". "; break;
		}
	}
	else
	{
		if ($minuteswalked<1)
		{
			switch (rand(1,6)) {
				case 1; $chapter .= "Right around the corner was ".$startpoint.". "; break;
				case 2; $chapter .= "We ".randString("walked","strolled","wandered")." a short distance to ".$startpoint.". "; break;
				case 3; $chapter .= "We approached ".$startpoint.". "; break;
				case 4; $chapter .= "Nearby was ".$startpoint.". "; break;
				case 5; $chapter .= "Close by was ".$startpoint.". "; break;
				case 6; $chapter .= "This was also the location of ".$startpoint.". "; break;
			}
		}
		elseif ($minuteswalked<20)
		{
			$passing = randString("Crossing a main road","Moving through the crowds");
			if ($passedplace <> "") { $passing = "Passing $passedplace"; $passedplace = ""; }
			switch (rand(1,11)) {
				case 1; $chapter .= "We ".randString("walked at a brisk pace","strolled","wandered","walked")." to ".$startpoint.". "; break;
				case 2; $chapter .= "We ".randString("walked","strolled","wandered")." a short distance to ".$startpoint.". "; break;
				case 3; $chapter .= "We ".randString("sprinted","ran")." to ".$startpoint.". "; break;
				case 4; $chapter .= "A few streets away was ".$startpoint.". "; break;
				case 5; $chapter .= "Moving on, we arrived at ".$startpoint.". "; break;
				case 6; $chapter .= "With ".randString("some urgency","no time to spare","no time to lose").", we ".randString("ran","walked")." to ".$startpoint.". "; break;
				case 7; $chapter .= "It was a short walk to ".$startpoint.". "; break;
				case 8; $chapter .= "$ourgroup walked to ".$startpoint.". "; break;
				case 9; $chapter .= "$traveller suggested that we ".randString("pay a visit to","visit")." ".$startpoint.". "; break;
				case 10; $chapter .= "$passing, we approached ".$startpoint.". "; break;
				case 11; $chapter .= "";
					
				$newweather = rand(1,9);
				while ($newweather == $weather) { $newweather = rand(1,9); }

				$weather = $newweather;
				switch ($weather) {
					case 1; $chapter .= "It began to rain"; break;
					case 2; $chapter .= "The sun came out"; break;
					case 3; $chapter .= "The sky clouded over"; break;
					case 4; $chapter .= "A cold wind picked up"; break;
					case 5; $chapter .= "The sky darkened"; break;
					case 6; $chapter .= "A fog descended"; break;
					case 7; $chapter .= "The weather improved"; break;
					case 8; $chapter .= "The weather worsened"; break;
					case 9; $chapter .= "Thunder cracked in the distance"; break;
				}
				$chapter .= " as we approached ".$startpoint.". "; break;
			}
		}
		elseif ($minuteswalked<60)
		{
			if ($localguide != "" && rand(1,10)==1)
			{
				switch (rand(1,2)) {
					case 1; $chapter .= "$localguide gave us a lift to ".$startpoint.". "; break;
					case 2; $chapter .= "$localguide drove us to ".$startpoint.". "; break;
				}
			}
			else
			{
				switch (rand(1,10)) {
					case 1; $chapter .= "We caught a cab to ".$startpoint.". "; break;
					case 2; $chapter .= "We hailed a cab to ".$startpoint.". "; break;
					case 3; $chapter .= "We hitched a lift to ".$startpoint.". "; break;
					case 4; $chapter .= "Some distance further was ".$startpoint.". "; break;
					case 5; $chapter .= "Our next stop was ".$startpoint.". "; break;
					case 6; $chapter .= "Moving on, we arrived at ".$startpoint.". "; break;
					case 7; $chapter .= "With no time to lose, we travelled to ".$startpoint.". "; break;
					case 8; $chapter .= "We made our way to ".$startpoint.". "; break;
					case 9; $chapter .= "$ourgroup hitched a lift to ".$startpoint.". "; break;
					case 10; $chapter .= "$traveller flagged down a bus to ".$startpoint.". "; break;
				}
			}
		}
		elseif ($minuteswalked<120)
		{
			if (!preg_match("/station/",$startpoint) && $laststation != "")
			{
				$chapter .= "".randString("With poor weather ahead, we ","Lost, we ","Unable to travel further on foot, we","We still had a long way to go, so we ","We")." ".randString("retraced our steps to","doubled back to","made our way to","walked to")." $laststation and ";
				
				if (preg_match("/station/",$laststation))
				{ $chapter .= "caught ".randString("an express","a","the next")." train, alighting near ".$startpoint.". "; }
				elseif (preg_match("/airport/",$laststation))
				{ $chapter .= "booked ourselves onto ".randString("a private","a","the next")." plane, alighting near ".$startpoint.". "; }
				elseif (preg_match("/(dock|port)/",$laststation))
				{ $chapter .= "arranged passage on ".randString("a fishing","a passenger","a","the next")." boat. Some time later, it docked near ".$startpoint." and we walked the rest of the way. "; }
				else
				{ $chapter .= "arranged transport to ".$startpoint.". "; }
				$laststation = "";
			}
			else
			{
			switch (rand(1,5)) {
				case 1; $chapter .= "We alighted from a bus ".randString("not too far from","near")." ".$startpoint.". "; break;
				case 2; $chapter .= "Our train arrived ".randString("not too far from","near")." ".$startpoint.". "; break;
				case 3; $chapter .= "We chartered a private plane which touched down ".randString("not too far from","near")." ".$startpoint.". "; break;
				case 4; $chapter .= "Our coach pulled up at ".$startpoint.". "; break;
				case 5; $chapter .= "We parked ".randString("not too far from","near")." ".$startpoint.". "; break;
			}
			}
		}
		else
		{
			if (!preg_match("/station/",$startpoint) && $laststation != "")
			{
				$chapter .= "".randString("The weather was worsening, so we ","Lost, we ","Time was running short, so we ","We")." ".randString("retraced our steps to","doubled back to","made our way to","walked to")." $laststation and ";
				
				if (preg_match("/station/",$laststation))
				{ $chapter .= "caught ".randString("an express","a","the next")." train, alighting near ".$startpoint.". "; }
				elseif (preg_match("/airport/",$laststation))
				{ $chapter .= "booked ourselves onto ".randString("a private","a","the next")." plane, alighting near ".$startpoint.". "; }
				elseif (preg_match("/(dock|port)/",$laststation))
				{ $chapter .= "arranged passage on ".randString("a fishing","a passenger","a","the next")." boat. Some time later, it docked near ".$startpoint." and we walked the rest of the way. "; }
				else
				{ $chapter .= "arranged transport to ".$startpoint.". "; }
				$laststation = "";
			}
			else
			{
			switch (rand(1,5)) {
				case 1; $chapter .= "We alighted from a ".randString("coach","bus")." near ".$startpoint.". "; break;
				case 2; $chapter .= "Our train arrived near ".$startpoint.". "; break;
				case 3; $chapter .= "Much later we arrived near ".$startpoint.". "; break;
				case 4; $chapter .= "Our ".randString("bus","coach")." pulled up at ".$startpoint.". "; break;
				case 5; $chapter .= "We parked near ".$startpoint.". "; break;
			}
			}
		}
	}
	
	$bracketedarticle = "(its |the |their |his |her |a |an )?";
	$mainwas = ""; $secondarywas = ""; $wasoff = 0; $wasphrase = rand(1,10);
	
	if (preg_match("/ leads? to([^\".,]{10,100})[.,]/",$article,$matches))
	{
		$chapter .= cleanLine("$speaker ".randString("made a joke about","told us a long story about","pointed out","talked about")." ".$matches[1].". ");
	}
	if (preg_match("/ was ([^.,]{20,100})[.,]/",$article,$matches,PREG_OFFSET_CAPTURE))
	{
		list($mainwas,$wasoff) = $matches[1];
		
		switch ($wasphrase) {
			case 1; $chapter .= cleanLine("$speaker told me it was ".$mainwas.". "); break;
			case 2; $chapter .= cleanLine("I could see that it was ".$mainwas.". "); break;
			case 3; $chapter .= cleanLine("It was clearly ".$mainwas.". "); break;
			case 4; $chapter .= cleanLine("Unless I was ".randString("very much mistaken","mistaken").", this was ".$mainwas.". "); break;
			case 5; $chapter .= cleanLine("I ".randString("recalled","remembered")." it was ".$mainwas.". "); break;
			case 6; $chapter .= cleanLine("My guidebook ".randString("told me","claimed")." it was ".$mainwas.". "); break;
			case 7; $chapter .= cleanLine("It looked as if it was ".$mainwas.". "); break;
			case 8; $chapter .= cleanLine("$traveller asked me if it was ".$mainwas.", but I did not know. "); break;
			case 9; $chapter .= cleanLine("".randString("As every schoolboy knows",
			"To the best of my recollection","As far as I could remember","If I recalled correctly",
			"To the best of my knowledge","As far as I knew","If I remembered correctly").", this was ".$mainwas.". "); break;
			case 10; $chapter .= cleanLine("Imagine my ".randString("amazement","astonishment","surprise")." to learn it was ".$mainwas."! "); break;
			}
	}
	if ($wasoff>0 && preg_match("/ was ([^.,]{20,100})[.,]/",$article,$matches,NULL,$wasoff))
	{
		$secondarywas = $matches[1]; //$chapter .= "WHAT'S MORE: ";

		$secondphrase = rand(1,10);
		while ($secondphrase == $wasphrase)
		{ $secondphrase = rand(1,10); }
		$secondspeech = $traveller;
		if ($wasphrase == 8 || ($wasphrase == 1 && $speaker == $traveller)) { $secondspeech = "He"; }
		
		  switch ($secondphrase) {
			case 1; $chapter .= cleanLine("$secondspeech said it was ".$matches[1].". "); break;
			case 2; $chapter .= cleanLine("I could see that it was ".$matches[1].". "); break;
			case 3; $chapter .= cleanLine("It was clearly ".$matches[1].". "); break;
			case 4; $chapter .= cleanLine("Unless I was ".randString("thinking of something else","very much mistaken","mistaken").", this was ".$matches[1].". "); break;
			case 5; $chapter .= cleanLine("I ".randString("recalled","remembered")." it was ".$matches[1].". "); break;
			case 6; $chapter .= cleanLine("My guidebook ".randString("said","claimed")." it was ".$matches[1].". "); break;
			case 7; $chapter .= cleanLine("It looked as if it was ".$matches[1].". "); break;
			case 8; $chapter .= cleanLine("$secondspeech asked me if it was ".$matches[1].", but I did not know. "); break;
			case 9; $chapter .= cleanLine("".randString("To the best of my knowledge","As far as I knew","If I remembered correctly").", this was ".$matches[1].". "); break;
			case 10; $chapter .= cleanLine("Imagine my ".randString("astonishment","surprise")." to learn it was ".$matches[1]."! "); break;
			}
	}
	if (preg_match("/ (was|did) not ([^.,]{10,100})[.,]/",$article,$matches))
	{
		$was = $matches[1];
		$subject = $matches[2];
		
		if ("not ".$subject != $mainwas && "not ".$subject != $secondarywas)
		{
			if (preg_match("/\b(him|his|himself|he)\b/",$subject,$submatches))
			{ $chapter .= cleanLine("$traveller ".randString("admitted","said")." that he ".$was."n't ".$matches[2].". "); }
			elseif (preg_match("/\b(her|herself|she)\b/",$subject,$submatches))
			{ $chapter .= cleanLine("$traveller ".randString("believed","commented")." that she ".$was."n't ".$matches[2].". "); }
			elseif (preg_match("/(their|them|themselves|they)/",$subject,$submatches))
			{ $chapter .= cleanLine("$traveller ".randString("remarked","commented","observed")." that they ".$was."n't ".$matches[2].". "); }
			elseif (preg_match("/^(support|believe|think|feel)/",$subject,$submatches))
			{ $chapter .= cleanLine("$traveller ".randString("admitted","remarked","said")." that he ".$was."n't ".$matches[2].". "); }
			else
			{ $chapter .= cleanLine("$traveller ".randString("commented","remarked","observed")." that it ".$was."n't ".$matches[2].". "); }
		}
	}
	if (preg_match("/(was|is) home (of|to) ([^.,]{10,100})[.,]/",$article,$matches) && !preg_match("/home/",$mainwas))
	{
		if ("home of ".$matches[3] != $mainwas && "home of ".$matches[3] != $secondarywas && "home to ".$matches[3] != $mainwas && "home to ".$matches[3] != $secondarywas)
		{
			$chapter .= cleanLine("We visited ".$matches[3].". ");
		}
	}
	if (preg_match("/ gave its name to $bracketedarticle([^.,]{10,100})[.,]/",$article,$matches))
	{
		$chapter .= cleanLine(randString("$speaker joked about","$speaker talked about","I recalled")." the ".$matches[2]." of the same name. ");
	}
	if (preg_match("/ commemorates ([^.,]{10,100})[.,]/",$article,$matches))
	{
		$chapter .= cleanLine("$traveller and I ".randString("silently remembered","reminisced about","swapped stories about","recalled")." ".$matches[1].". ");
	}
	if (preg_match("/(this|it) became ([^.,]{6,100})[.,]/",$article,$matches))
	{
		$chapter .= cleanLine("$speaker remembered it becoming ".$matches[2].". ");
	}
	if (preg_match("/[Ww]hich would be ([^.,]{6,100})[.,]/",$article,$matches))
	{
		$chapter .= cleanLine("We ".randString("disagreed as to whether","thought","agreed")." it was ".$matches[1].". ");
	}
	if (preg_match("/produced ([^.,]{12,100})[.,]/",$article,$matches))
	{
		$chapter .= cleanLine(randString("$speaker and I","We")." enjoyed ".$matches[1].". ");
	}
	if (preg_match("/there (were|are) (five|six|seven|eight|nine|ten) ([A-Za-z\-\']+s) /",$article,$matches))
	{
	  $plus = "six";
	  if ($matches[2]=="six") { $plus = "seven"; } 
	  if ($matches[2]=="seven") { $plus = "eight"; } 
	  if ($matches[2]=="eight") { $plus = "nine"; } 
	  if ($matches[2]=="nine") { $plus = "ten"; } 
	  if ($matches[2]=="ten") { $plus = "eleven"; } 
		$chapter .= cleanLine("Were there ".$matches[2]." or ".$plus." ".$matches[3]."? $traveller ".randString("didn't seem to care","wasn't sure","thought ".$matches[2]).". ");
	}
	if (preg_match("/ still (retain|show|feature)s? some (of )?$bracketedarticle([^.,]+)[.,]/",$article,$matches))
	{
		$chapter .= cleanLine("I admired the ".$matches[4].". ");
	}
	if (preg_match("/where ([\w ]+) is located/",$article,$matches))
	{
		$chapter .= cleanLine("We had a".randString("marvellous","good","n excellent"," fine")." view of ".$matches[1]." from here. ");
	}
	if (preg_match("/with a ([\w ]+) design/",$article,$matches))
	{
		$chapter .= cleanLine("We ".randString("argued over the merits of","considered","admired","noted")." its ".$matches[1]." design. ");
	}
	if (preg_match("/(has|uses) (an? )([^.,]{6,100})[,.]/",$article,$matches)) // was ending on " and"
	{
		$chapter .= cleanLine("".randString("We joined some tourists who were admiring","$speaker and I admired","I admired","We admired")." the ".$matches[3].". ");
	}
	if (preg_match("/used as ([^.,]{6,100})[,.]/",$article,$matches)) 
	{
		if (rand(1,2)==1)
		{ $chapter .= cleanLine("It ".randString("was hard to believe it was ever","functioned well as")." ".$matches[1].". "); }
		else
		{
			$question = cleanLine("%$traveller%\"".randString("Was this really","Are you sure this was","Did you say this was")." ".$matches[1]."?\" ".randString("wondered","asked")." $traveller. ");
			$answer = cleanLine("%narrator%\"".randString("See for yourself","Now you ask, I am not so sure","I believe so","But of course","Naturally","Certainly","I think so","Yes").".\" I ".randString("said","replied").". ");
			
			if ($question != "" && $answer != "")
			{ $chapter .= $question.$answer; }
		}
	}
	elseif (preg_match("/used for ([^.,]{6,100})[,.]/",$article,$matches)) 
	{
		if (rand(1,2)==1)
	  { $chapter .= cleanLine("It seemed ".randString("a fine spot","quite suitable","perfect")." for ".$matches[1].". "); }
	  else
	  { $chapter .= cleanLine("%$traveller%\"".randString("I can't imagine a worse place","I imagine this is a place","I suppose it's alright","I wonder if this is a place")." for ".$matches[1].".\" said $traveller. "); }
	}
	if (preg_match("/an example of $bracketedarticle([^.,]{6,100})[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("$traveller took ".randString("several photographs of","notes on","a photograph of")." the ".$matches[2].". ");
	}
	if (preg_match("/the (noise|sound) of $bracketedarticle([^.,]+)[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("I could hardly hear $speaker over the ".randString("noise","sound")." of the ".$matches[3].". ");
	}
	if (preg_match("/intended to ([^.,]+)[,.]/",$article,$matches))
	{
		if (rand(1,2) == 1)
		{
			if (preg_match("/^be (.+)$/",$matches[1],$morematches))
			{ $chapter .= cleanLine("Was it ".$morematches[1]."? We ".randString("thought so","thought not","were not sure").". "); }
			else
			{ $chapter .= cleanLine("Did it ".$matches[1]."? We ".randString("thought so","thought not","were not sure").". "); }
		}
		else
		{
			if (preg_match("/^be (.+)$/",$matches[1],$morematches))
			{ $chapter .= cleanLine("*$traveller*\"Was it ".$morematches[1]."?\" asked $traveller. ");
			  if ($localguide != "" && rand(1,2)==1)
			  { $chapter .= cleanLine("*narrator*\"I ".randString("couldn't care less","think so","doubt it","think not","am not sure","believe so")."?\" said $localguide."); }
		      else
			  { $chapter .= cleanLine("*narrator*\"I ".randString("think so","doubt it","think not","think not","am not sure")."?\" I said."); }
		  
			}
			else
			{ $chapter .= cleanLine("*$traveller*\"Did it ".$matches[1]."?\" asked $traveller. ");
			  if ($localguide != "" && rand(1,2)==1)
			  { $chapter .= cleanLine("*narrator*\"I ".randString("couldn't care less","think so","doubt it","think not","believe so","am not sure").".\" said $localguide."); }
			  else
			  { $chapter .= cleanLine("*narrator*\"I ".randString("think so","doubt it","think not","think not","am not sure").".\" I said."); }
			}
		}
	}
	if (preg_match("/(contains|houses|housed|contained) (an|a|the|some) ([^.,]{20,100})[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("".randString("I tripped over","$traveller held a magnifying glass up to","$traveller examined","$traveller was unimpressed by","I found and admired")." ".$matches[2]." ".$matches[3].". ");
	}
	elseif (preg_match("/(contains) ([^.,]+)[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("I spent ".randString("over an hour","a short time","a few minutes","some time","a while")." ".randString("perusing","studying","examining")." ".$matches[2].". ");
	}
	if (preg_match("/access to ([^.,]+)[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("It ".randString("was certainly handy for","was handy for","was within convenient distance of","was convenient for","seemed handy for")." ".$matches[1].". ");
	}
	if (preg_match("/provides ([^.,]+)[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("We ".randString("helped ourselves to","made full benefit of","took advantage of")." ".$matches[1].". ");
	}
	if (preg_match("/in common with ([^.,]+)[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("It seemed ".randString("indistinguishable from","broadly similar to","quite similar to")." ".$matches[1].". ");
	}
	if (preg_match("/was (subsequently|eventually) ([^.,]{6,100})[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("$traveller ".randString("recalled the time before it was","mourned it having been","recounted how it had been","spoke of the time when it was")." ".$matches[2].". ");
	}
	if (preg_match("/known for (the|its|their) ([^.,]+)[,.]/",$article,$matches))
	{
		if (rand(1,2)==1)
		{ $chapter .= cleanLine("We ".randString("took some time to enjoy","admired","enjoyed")." the ".randString("legendary","famous")." ".$matches[2].". "); }
		else
		{ $chapter .= cleanLine("%$traveller%\"".randString("Look! The","Look at the","Just look at the")." ".$matches[2]."!\" said $traveller. "); }
		
	}
	if (preg_match("/few (of the |of its )?([^.,]{6,100}) (remain|survive)/",$article,$matches))
	{
		$chapter .= cleanLine("We looked for ".$matches[2]." but ".randString("struggled to","weren't able to","could not")." find any. ");
	}
	if (preg_match("/designed to ([^.,]+)[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("$speaker ".randString("explained to us","explained")." how it had been designed to ".$matches[1].". ");
	}
	if (preg_match("/was (apparently|probably) ([^.,]+)[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("$speaker ".randString("whispered","said")." it was ".randString("rumoured","believed","thought")." to have been ".$matches[2].". ");
	}
	if (preg_match("/it would be ([^.,]+)[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("$traveller disapproved of it being ".$matches[1].". ");
	}
	if (preg_match("/connected by $bracketedarticle([^.,]+)[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("We traversed the ".$matches[2].". ");
	}
	if (preg_match("/until (after )?([^12][^.,]{30,100})[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("".randString("Times certainly changed","The mood here changed","Things were never the same","Things changed","Things were different")." after ".$matches[2].". ");
	}
	if (preg_match("/a production of ([^.,]{10,30})[,.]/",$article,$matches))
	{
		$chapter .= cleanLine("We ".randString("attended a disappointing","attended a mediocre","enjoyed an adequate","enjoyed a fine")." production of ".$matches[1].". ");
	}
	if (preg_match("/(signed|uilt|irected|culpted) by ([A-Z][^ ,\.]{3,20}) [A-Z]/",$article,$matches) && $localguide == "")
	{
		$stranger = $matches[2];

		if (!strpos($chapter,$stranger)) // Only use a name if we've not already mentioned it.
		{
			$enterstageleft = "";
			if (rand(1,2)==1)
			{ $enterstageleft = cleanLine("We ".randString("were hailed by","were greeted by","bumped into","entered into conversation with","were approached by","encountered").
									" a".
									randString(" mysterious figure"," taxi driver"," dishevelled character"," local shopkeeper"," passer-by"," fellow tourist"," local resident"," local").
									", who introduced themselves as ".$stranger.". "); }
			else
			{ $enterstageleft = cleanLine("We met ".$stranger.", a".
									randString("n old friend and terrible bore","n old friend of ".$traveller."'s"," college friend of mine","n old colleague of mine","n old friend of mine").
									" who ".
									randString("pulled up in a car","worked nearby","had heard about our journey","was in the area","lived nearby","was passing by").". "); }
			
			if ($enterstageleft != "")
			{
				$chapter .= $enterstageleft;
				$localguide = $stranger;
				$localguidehome = $startpoint;
			}
		}
	}
	elseif (preg_match("/ (tavern|pub|restaurant|train station|hostel|hotel|cinema|theatre|shop|bar|museum|house) /",$article,$matches) && rand(1,3)==1 && $localguide <> "")
	{
		if (rand(1,2)==1)
		{ $chapter .= cleanLine("At this point, $localguide ".randString("hailed a cab","departed from our company","noticed the time and said they had to leave","had to leave","reluctantly left us").", saying that they had ".randString("to return to","to return home via","business to attend to back at")." $localguidehome. "); }
		else
		{ $chapter .= cleanLine("At this point, $localguide entered a nearby ".$matches[1]." and bade us farewell. "); }
		$localguide = "";
	}
	
	if (preg_match("/statue of \[\[([^\]]+)\]\]/",$original,$matches) && !preg_match("/[Ss]tatue/",$startpoint))
	{
		$statue = $matches[1];
		$statue = preg_replace("/\|.+$/","",$statue);		
		list($statueoriginal,$statuearticle) = fetchArticle($statue);
		if (preg_match("/ (is|was) ([^.,]{10,100})[.,]/",$statuearticle,$matches))
		{
			$chapter .= cleanLine("".randString("We couldn't fail to notice","$traveller looked up at","We noted","We admired")." the statue of ".$statue.", ");
			$chapter .= cleanLine("".$matches[2].". ");
			if (preg_match("/wore ([^.,]{10,100})[.,]/",$statuearticle,$matches))
			{
				$chapter .= cleanLine("$traveller thought the statue should have been wearing ".$matches[1].". ");
			}
			elseif (preg_match("/dressed in ([^.,]{10,100})[.,]/",$statuearticle,$matches))
			{
				$chapter .= cleanLine("$traveller thought the statue should have been wearing ".$matches[1].". ");
			}
			if (preg_match("/\"([^.,]{10,100})\",? (s?he) said/",$statuearticle,$matches))
			{
				$chapter .= cleanLine("Who could forget that famous line, \"".$matches[1]."\". ");
			}
			if (preg_match("/ had a ([^.,]{10,100})[.,]/",$statuearticle,$matches))
			{
				$chapter .= cleanLine("The sculptor had captured the ".$matches[1]." perfectly. ");
			}
			if (preg_match("/(s?he) (is|was) ([^.,]{10,100})[.,]/",$statuearticle,$matches))
			{
				$chapter .= cleanLine("".randString("We were surprised that","We were impressed that","To think that","It seemed fitting")." somebody who was ".$matches[3]." should have ".randString("such ","")."a statue in $startpoint. ");
			}
		}
		else
		{ 
			$chapter .= cleanLine("".randString("We couldn't fail to notice","$traveller looked up at","We noted","We admired")." the statue of ".$statue.". ");
		}
	}
	
	if (preg_match("/\"([A-Z][^.!\"]{10,200}\.)/",$article,$matches) && $localguide <> "")
	{
		$dialogue = $matches[1];
		$dialogue = preg_replace("/ .$/","...",$dialogue);
		$chapter .= cleanLine("%local%\"".$dialogue."\" said $localguide. ");
	}
	elseif (preg_match("/\"([A-Z][^.!\"]{10,200}!)/",$article,$matches) && $localguide <> "")
	{
		$chapter .= cleanLine("%local%\"".$matches[1]."\" exclaimed $localguide. ");
	}
	elseif (preg_match("/\"([A-Z][^\?\"]{10,200}\?)/",$article,$matches) && $localguide <> "")
	{
		$chapter .= cleanLine("%local%\"".$matches[1]."\" asked $localguide. ");
	}
	if (preg_match("/due to ([^b][^e][^.,]{6,100})[,.]/",$article,$matches)) 
	{
		$chapter .= cleanLine(randString("Our visit was cut short due to ","We had heard stories of ","We encounted some problems with ",
		"We ignored ",
		"We moved on, avoiding ","We moved on, disappointed by ","We moved on, unsure what to make of ",
		"We avoided ", "We noted ").$matches[1].". ");
	}
	
	return $chapter;
}
    $jsoni18nAssocArray[$defaultLangKey] = $jsoni18nAssocArray[$defaultLang];
}
$base_template = file_get_contents($gherkinTemplate);
$futureTemplate = array();
foreach ($jsoni18nAssocArray as $jsonKey => $jsonValue) {
    $tmp_template = $base_template;
    $tmp_firstLineMatchLine = "";
    $tmp_template = str_replace($smallLangWithADot, strcmp($jsonKey, $defaultLangKey) === 0 ? "" : "." . $jsonKey, $tmp_template);
    foreach ($templateKeys as $tKey => $tValue) {
        $explodedArray = cleanLine($jsonValue[$tValue["name"]]);
        $funcName = strlen($tValue["separator"]) > 0 ? "addQuote2" : "addQuote";
        $explodedArray = array_map($funcName, $explodedArray);
        $tmp_str = implode(PHP_EOL, $explodedArray);
        $tmp_template = str_replace($tKey, $tmp_str, $tmp_template);
    }
    $scenarios = cleanLine($jsonValue["scenario"]);
    $multipleIncreaseIndentPatternKey = str_repeat("      " . $increaseIndentPatternKey . (count($scenarios) > 1 ? PHP_EOL : ""), count($scenarios));
    $tmp_template = str_replace($increaseIndentPatternKey, $multipleIncreaseIndentPatternKey, $tmp_template);
    $tmp_template = str_replace($increaseIndentPatternKey, $increaseIndentPattern, $tmp_template);
    foreach ($scenarios as $unScenario) {
        $tmp_template = str_replace_first("__SCENARIO__", $unScenario, $tmp_template);
    }
    $futureTemplate[$jsonKey] = $tmp_template;
}
$gherkinPathInfo = pathinfo($gherkinTemplate);
foreach ($futureTemplate as $keyLang => $langTemplateContent) {
    $dirname = $gherkinPathInfo['dirname'];
    $tmpFilename = "";
    if (strcmp($keyLang, $defaultLangKey) !== 0) {
        $tmpFilename = $dirname . "/scoped-properties/" . $gherkinGeneratedFilename . "_" . $keyLang . "." . $gherkinGeneratedExtension;
    } else {