var q = new Array(13);

	q[0] =  " (: Retrieve summary and 'see also' links for the article 'User-generated content'\n   (this query addresses article's content)  :)  \n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";  \n\n"+
			"let $a := index-scan('article-by-title','User-generated content','EQ')\n"+
			"return \n"+
			"  <summary> \n"+
			"    <title>{$a/title}</title> \n"+
			"    <body>{($a/revision/text//p)[1]}</body> \n"+
			"    <seealso>{$a/revision/text/section[title='See also']//link}</seealso> \n"+
			"  </summary>";

	q[1] =  " (: Tennis players from Moscow (this query addresses articles' infoboxes) :)  \n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";  \n\n"+
			"declare ordering unordered; \n\n" +
			"index-scan('article-by-cat','Category:Russian tennis players','EQ')[contains(.//template[@head=\"Infobox Tennis player\"]/field[@name=\"residence\"]/string(),\"Moscow\")]/title";
			

	q[2] = 	" (: Find redirects (i.e. synonyms) to a given article :) \n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";\n"+
			"declare ordering unordered; \n\n" +
			"index-scan('article-by-link',\n           'Ivan IV of Russia',\n           'EQ')[revision/text/redirect]/title/text()";

	q[3] =	" (: Retrieve the 'History' section of the 'NASA' article :)\n\n" +
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";\n\n" +
			"index-scan('article-by-title','NASA','EQ')/revision/text/section[title = 'History']";

	q[4] =	" (: Retrieve all links from a given article :)\n\n" +
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";\n\n" +
			"index-scan('article-by-title','Data mining','EQ')//link/@label/string(.)";

	q[5] = 	" (: Full text search by 'sedna xml' :) \n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";\n"+
			"declare ordering unordered; \n\n" +
			"ftindex-scan('fti','sedna xml')/title/text()";


	q[6] = 	" (: Retrieve all articles with 'Sedna' in title :) \n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";\n"+
			"declare ordering unordered; \n\n" +
			"ftindex-scan('fti','(title contains sedna)')/title/text()";


	q[7] = 	" (: Find Danish mathematicians :) \n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";\n"+
			"declare ordering unordered; \n\n" +
			"index-scan('article-by-cat','Category:Danish mathematicians','EQ')/title/text()";
		   
		   
	q[8] =	" (: Get all articles that referes to the 'Norway' article which belong\n    to 'Computer pioneers' category :)\n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";\n\n" +
			"(index-scan('article-by-link','Norway','EQ') \n"+
			"intersect \n"+
			"index-scan('article-by-cat',\n           'Category:Computer pioneers',\n           'EQ'))/title/text()";
		   

	q[9] =	" (: Summary of commercial text mining tools :)\n\n" +
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";\n" +
			"declare ordering unordered;\n\n" +
			"for $name in index-scan('article-by-title','Text mining','EQ')\n"+
			"    /revision/text//section[title=\"Software and applications\"]//link/@label\n"+
			"let $company := index-scan('article-by-title',$name,'EQ')\n"+
			"return \n"+
			"  <summary> \n"+
			"    <title>{$name/string()}</title> \n"+
			"    {$company/revision/text//p[1]} \n"+
			"  </summary>";
			

	q[10] = " (: Retrieve all neighbors of a given article  \n"+
			"    (i.e. all articles which are reffered by a given article) :)\n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";  \n"+
			"declare ordering unordered; \n\n" +
			"declare function local:neighbors($title as xs:string) as node()* {  \n"+
			"  for $n in index-scan('article-by-title',$title,'EQ')//link/@label  \n"+
			"  return  \n"+
			"     index-scan('article-by-title',$n,'EQ') \n"+
			"}; \n\n"+
			"local:neighbors(\"MapReduce\")/title/text()";
			
		   
	q[11] =	" (: Retrieve all dual-neighbors of a given article  \n"+
			"    (i.e. all articles which are reffered by and refers to a given article):)  \n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";  \n\n"+
			"declare function local:dual-neighbors($title as xs:string) as node()* {  \n"+
			" (for $link in index-scan('article-by-title',$title,'EQ')//link/@label  \n"+
			"  return index-scan('article-by-title',$link,'EQ'))  \n"+
			"    intersect \n"+
			"  index-scan('article-by-link',$title,'EQ')  \n"+
			"};  \n\n"+
			"local:dual-neighbors(\"MapReduce\")/title/text()";
		   
	q[12] = " (: Compare Dice and Jaccard coeffs for all\n     dual-neighbors of the target article :)\n\n"+
			"declare default element namespace \"http://www.mediawiki.org/xml/export-0.5/\";  \n"+
			"declare ordering unordered; \n\n" +
			"declare function local:neighbors($title as xs:string) as node()* {  \n"+
			"  for $n in index-scan('article-by-title',$title,'EQ')//link/@label  \n"+
			"  return  \n"+
			"     index-scan('article-by-title',$n,'EQ') \n"+
			"}; \n\n"+
			"declare function local:dual-neighbors($title as xs:string) as node()* {  \n"+
			" (for $link in index-scan('article-by-title',$title,'EQ')//link/@label  \n"+
			"  return index-scan('article-by-title',$link,'EQ'))  \n"+
			"    intersect \n"+
			"  index-scan('article-by-link',$title,'EQ')  \n"+
			"};  \n\n"+
			"declare function local:dice-coeff($n1 as node()*, $n2 as node()*) as xs:double { \n"+
			"  count($n1 intersect $n2) \n"+
			"  div \n"+
			"  (count($n1)+count($n2)) \n"+
			"}; \n\n"+
			"declare function local:jaccard-coeff($n1 as node()*, $n2 as node()*) as xs:double { \n"+
			"  count($n1 intersect $n2) \n"+
			"  div \n"+
			"  count($n1 union $n2) \n"+
			"}; \n\n"+
			"let $target-title:='Anarchism', \n"+
			"    $neighbors := local:neighbors($target-title), \n"+
			"    $dual-neighbors := local:dual-neighbors($target-title) \n"+
			"return \n"+
			"	for $a in $dual-neighbors \n"+
			"	let $an := local:neighbors($a/title/text()), \n"+
			"            $dice-coeff := local:dice-coeff($neighbors, $an), \n"+
			"            $jaccard-coeff := local:jaccard-coeff($neighbors, $an) \n"+
			"	order by $dice-coeff \n"+
			"	return \n"+
			"       <dual-neighbor target-artile=\"{$target-title}\"> \n"+
			"           <dual-neighbor>{$a/title/text()}</dual-neighbor> \n"+
			"           <dice>{$dice-coeff}</dice> \n"+
			"           <jaccard>{$jaccard-coeff}</jaccard> \n"+
			"       </dual-neighbor> \n";

function predefinedQuery(num) {
	editAreaLoader.setValue("qid", q[num]);
}


