Last active
August 28, 2015 15:26
-
-
Save CliffordAnderson/3f15ab0776e141c85169 to your computer and use it in GitHub Desktop.
Examples for XQuery Workgroup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
import module namespace corpus = "http://library.vanderbilt.edu/baudelaire" at "corpus.xqm"; | |
corpus:search("chat") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
module namespace corpus = "http://library.vanderbilt.edu/baudelaire"; | |
declare namespace tei = "http://www.tei-c.org/ns/1.0"; | |
declare variable $corpus:db := fn:collection("fleurs-du-mal"); | |
declare function corpus:search($term as xs:string*) as item()* | |
{ | |
$corpus:db//tei:l[text() contains text {$term}] | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
module namespace corpus = "http://library.vanderbilt.edu/baudelaire"; | |
declare namespace tei = "http://www.tei-c.org/ns/1.0"; | |
declare variable $corpus:db := fn:collection("fleurs-du-mal"); | |
declare function corpus:search($term as xs:string*) as item()* | |
{ | |
let $results := $corpus:db//tei:l[text() contains text {$term}] | |
for $result in $results | |
let $score := ft:score($result[text() contains text {$term}]) | |
let $snippet := ft:extract($result/text()[. contains text {$term}], "b") | |
let $base-uri := fn:base-uri($result) | |
let $line := $result/@n | |
order by $score descending | |
where $base-uri != "fleurs-du-mal/fleurs-du-mal.xml" | |
return | |
element p { | |
attribute score {$score}, | |
attribute base-uri {$base-uri}, | |
attribute line {$line}, | |
$snippet | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
module namespace corpus = "http://library.vanderbilt.edu/baudelaire"; | |
declare namespace tei = "http://www.tei-c.org/ns/1.0"; | |
declare variable $corpus:db := fn:collection("fleurs-du-mal"); | |
declare function corpus:search($term as xs:string*) as item()* | |
{( | |
let $results := $corpus:db//tei:l[text() contains text {$term}] | |
for $result in $results | |
let $score := ft:score($result[text() contains text {$term}]) | |
let $snippet := ft:extract($result/text()[. contains text {$term}], "b") | |
let $base-uri := fn:base-uri($result) | |
let $line := $result/@n | |
order by $score descending | |
where $base-uri != "fleurs-du-mal/fleurs-du-mal.xml" | |
return | |
element p { | |
attribute score {$score}, | |
attribute base-uri {$base-uri}, | |
attribute line {$line}, | |
$snippet | |
}) => corpus:format() | |
}; | |
declare function corpus:format($results as element(p)*) as element(html) | |
{ | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> | |
<meta name="viewport" content="width=device-width, initial-scale=1"/> | |
<title>Corpus Baudelaire - Search Results</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> | |
</head> | |
<body> | |
<div class="container-fluid"> | |
<h1>Search Results</h1> | |
{for $result in $results | |
return | |
element p { | |
"Line " || $result/@line || ": " , | |
$result/node(), | |
element a { | |
attribute href {$result/@base-uri}, | |
"...(read more)." | |
} | |
} | |
} | |
</div> | |
</body> | |
</html> | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
module namespace corpus = "http://library.vanderbilt.edu/baudelaire"; | |
declare namespace tei = "http://www.tei-c.org/ns/1.0"; | |
declare variable $corpus:db := fn:collection("fleurs-du-mal"); | |
declare | |
%rest:GET | |
%rest:path("/search") | |
%rest:query-param("q","{$term}") | |
%output:method("xhtml") | |
%output:omit-xml-declaration("no") | |
%output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN") | |
function corpus:search($term as xs:string*) as item()* | |
{( | |
let $results := $corpus:db//tei:l[text() contains text {$term}] | |
for $result in $results | |
let $score := ft:score($result[text() contains text {$term}]) | |
let $snippet := ft:extract($result/text()[. contains text {$term}], "b") | |
let $base-uri := fn:base-uri($result) | |
let $line := $result/@n | |
order by $score descending | |
where $base-uri != "fleurs-du-mal/fleurs-du-mal.xml" | |
return | |
element p { | |
attribute score {$score}, | |
attribute base-uri {$base-uri}, | |
attribute line {$line}, | |
$snippet | |
}) => corpus:format() | |
}; | |
declare function corpus:format($results as element(p)*) as element(html) | |
{ | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> | |
<meta name="viewport" content="width=device-width, initial-scale=1"/> | |
<title>Corpus Baudelaire - Search Results</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"/> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> | |
</head> | |
<body> | |
<div class="container-fluid"> | |
<h1>Search Results</h1> | |
{for $result in $results | |
return | |
element p { | |
"Line " || $result/@line || ": " , | |
$result/node(), | |
element a { | |
attribute href {$result/@base-uri}, | |
"...(read more)." | |
} | |
} | |
} | |
</div> | |
</body> | |
</html> | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Corpus Baudelaire - Search Results</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> | |
</head> | |
<body> | |
<div class="container-fluid"> | |
<h1>Search Results</h1> | |
<p>Line 22: <b>Chat</b> sérafique, <b>chat</b> étrange,<a href="fleurs-du-mal/FDM-047-051-000-052.xml">...(read more).</a> | |
</p> | |
<p>Line 10: Des <b>chats</b> passaient furtivement,<a href="fleurs-du-mal/FDM-041-045-000-046.xml">...(read more).</a> | |
</p> | |
<p>Line 21: que ta voix, <b>chat</b> mystérieux,<a href="fleurs-du-mal/FDM-047-051-000-052.xml">...(read more).</a> | |
</p> | |
<p>Line 3: Un beau <b>chat</b>, fort, doux et charmant.<a href="fleurs-du-mal/FDM-047-051-000-052.xml">...(read more).</a> | |
</p> | |
<p>Line 1: Viens, mon beau <b>chat</b>, sur mon coeur amoureux:<a href="fleurs-du-mal/FDM-033-034-000-035.xml">...(read more).</a> | |
</p> | |
<p>Line 5: Mon <b>chat</b> sur le carreau cherchant une litière<a href="fleurs-du-mal/FDM-059-075-000-077.xml">...(read more).</a> | |
</p> | |
<p>Line 4: Comme aux pieds d'une reine un <b>chat</b> voluptueux.<a href="fleurs-du-mal/FDM-019-019-000-020.xml">...(read more).</a> | |
</p> | |
<p>Line 9: Quand mes yeux, cers ce <b>chat</b> que j'aime<a href="fleurs-du-mal/FDM-047-051-000-052.xml">...(read more).</a> | |
</p> | |
<p>Line 3: Les <b>chats</b> puissants et doux, orgueil de la maison,<a href="fleurs-du-mal/FDM-056-066-000-068.xml">...(read more).</a> | |
</p> | |
<p>Line 9: Dans le ravin hanté des <b>chats</b>-pards et des onces<a href="fleurs-du-mal/FDM-000-035-000-036.xml">...(read more).</a> | |
</p> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment