Commit 0dff30dd authored by Michael Joyce's avatar Michael Joyce
Browse files

initial commit.

parents
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>Colocation Generator</h1>
</div>
</div>
</div>
<form class="form-horizontal" method="get" action="colocation.html">
<input type="hidden" name="id" data-template="templates:form-control"/>
<div class="row">
<div class="form-group">
<label class="col-sm-2 control-label" for="q">Colocation term</label>
<div class="col-sm-10">
<div class="input-group">
<input type="text" class="form-control" id="q" name="q" data-template="templates:form-control"/>
<div class="input-group-btn">
<button type="button" class="btn btn-primary">Colocate</button>
</div>
</div>
</div>
</div>
</div>
</form>
<div data-template="app:colocation-load">
<div class="row">
<div class="col-sm-12">
<div id="chart"/>
</div>
</div>
<div class="row">
<div data-template="app:colocation-count"/>
<div data-template="app:colocation-results"/>
</div>
</div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"/>
<script type="text/javascript" src="resources/js/url.js"/>
<script type="text/javascript" src="resources/js/colocation.js"/>
</div>
\ No newline at end of file
xquery version "3.0";
declare variable $exist:path external;
declare variable $exist:resource external;
declare variable $exist:controller external;
declare variable $exist:prefix external;
declare variable $exist:root external;
if ($exist:path eq '') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{request:get-uri()}/"/>
</dispatch>
else if ($exist:path eq "/") then
(: forward root path to index.xql :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="index.html"/>
</dispatch>
else if (ends-with($exist:resource, ".html")) then
(: the html page is run through view.xql to expand templates :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
<error-handler>
<forward url="{$exist:controller}/error-page.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
(: Resource paths starting with $shared are loaded from the shared-resources app :)
else if (contains($exist:path, "/$shared/")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="/shared-resources/{substring-after($exist:path, '/$shared/')}">
<set-header name="Cache-Control" value="max-age=3600, must-revalidate"/>
</forward>
</dispatch>
(: Very simple API endpoint. :)
else if(contains($exist:path, "/api/")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/api.xql">
<set-attribute name="function" value="{substring-after($exist:path, '/api/')}"/>
</forward>
</dispatch>
else
(: everything else is passed through :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<cache-control cache="yes"/>
</dispatch>
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_lite.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?><?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_lite.rng" type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Not found</title>
</titleStmt>
<publicationStmt>
<p>Placeholder document for items that are not in the database.</p>
</publicationStmt>
<sourceDesc>
<p>Born digital.</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<!--Note: page numbers in pb elements are generated programmatically and will likely not match the page numbers as printed on the book's pages.-->
<div type="book">
<pb n="1"/>
<p>The requested item could not be found.</p>
<pb n="2"/>
</div>
</body>
</text>
</TEI>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
<div data-template="app:document-load">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1 data-template="app:document-title">English 434 Teaching Tools</h1>
</div>
</div>
</div>
<div class="row">
<div data-template="app:document-nav"/>
<div class="col-sm-2 sidebar">
<div class="panel-group" id="side-controls">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Page Navigation
</h4>
</div>
<div class="panel-body">
<div id="page-nav" data-template="app:document-navigation"/>
</div>
</div>
<h2>Tools</h2>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#side-controls" href="#search-form">Search</a>
</h4>
</div>
<div id="search-form" class="panel-collapse collapse" data-template="app:search-form"/>
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#side-controls" href="#search-form">Concordance</a>
</h4>
</div>
<div id="concordance-form" class="panel-collapse collapse" data-template="app:concordance-form"/>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#side-controls" href="#tag-panel-content">Tags</a>
</h4>
</div>
<div id="tag-panel-content" class="panel-collapse collapse">
<div class="panel-body">
<p>Automatically recognized tags - click to toggle.</p>
</div>
<ul class="list-group" id="ner-controls">
<li class="list-group-item">
<a class="toggle-ent" data-ent="location">
Locations
</a>
</li>
<li class="list-group-item">
<a class="toggle-ent" data-ent="person">
Persons
</a>
</li>
<li class="list-group-item">
<a class="toggle-ent" data-ent="organization">
Organization
</a>
</li>
<li class="list-group-item">
<a class="toggle-ent" data-ent="date">
Dates &amp; Times
</a>
</li>
</ul>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#side-controls" href="#external-panel-content">External</a>
</h4>
</div>
<div id="external-panel-content" class="panel-collapse collapse">
<div class="panel-body">
<p>Third party tools. These links are prototypes only - they will not work.</p>
</div>
<ul class="list-group">
<li class="list-group-item">
Voyant:
<a href="#">Page</a> | <a href="s">Doc</a>
</li>
<li class="list-group-item">
Voyant:
<a href="#">Page</a> | <a href="s">Doc</a>
</li>
<li class="list-group-item">
Voyant:
<a href="#">Page</a> | <a href="s">Doc</a>
</li>
<li class="list-group-item">
Voyant:
<a href="#">Page</a> | <a href="s">Doc</a>
</li>
<li class="list-group-item">
Voyant:
<a href="#">Page</a> | <a href="s">Doc</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="col-sm-5">
<div id="document-content">
<div data-template="app:document-page"/>
</div>
</div>
<div class="col-sm-5">
<div data-template="app:document-facsimile"/>
</div>
</div>
</div>
<script type="text/javascript" src="resources/js/doc.js"/>
</div>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>Test the entity recognizer</h1>
</div>
</div>
</div>
<div class="row">
<form method="post">
<div class="form-group">
<label for="content">Content</label>
<textarea class="form-control" rows="6" cols="40" name="content" id="content"/>
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="Test"/>
</div>
</form>
</div>
<div class="row">
<div data-template="app:test-entities"/>
</div>
</div>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
<div class="jumbotron">
<div class="media">
<div class="media-left">
<a href="#">
<img class="media-object" src="resources/img/1956-tn.jpg"/>
</a>
</div>
<div class="media-body">
<h1 class="media-heading">Lake District Online Pedagogy Prototype</h1>
<h2 class="media-heading">Reading Digitally: The Book Up Close and At a
Distance</h2>
<blockquote>
<p>...a book is nowadays perhaps the most satisfactory work of art one can make
or have. The best work of art of all to create is a house... A book comes
next, and between a house and a book a man can do very well. </p>
<footer>
<cite>William Morris, 1893</cite>
</footer>
</blockquote>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="thumbnail">
<a href="resources/img/Wordsworth1835_5.png">
<img src="resources/img/Wordsworth1835_5-tn.png"/>
</a>
<div class="caption">
<h3>For the Use of Tourists and Residents</h3>
<p>Frontispiece map showing heights of mountains as well as distances; from
Wordsworth’s A Guide Through the District of the Lakes in the North of
England, with a Description of the Scenery, &amp;c. For the Use of Tourists
and Residents (1835).</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="thumbnail">
<a href="resources/img/Martineau1858-202.png">
<img src="resources/img/Martineau1858-202-tn.png"/>
</a>
<div class="caption">
<h3>Coloured Geologic Map</h3>
<p>Coloured Geologic Map [1855] from Harriet Martineau’s Description of the
English Lakes (1858) opp. p. 167. [sepia map]</p>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
<div data-template="app:location-load">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1 data-template="app:location-title">English 434 Teaching Tools</h1>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12" data-template="app:location-description"/>
</div>
</div>
</div>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
<div data-template="app:document-load">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1 data-template="app:document-title">English 434 Teaching Tools</h1>
</div>
</div>
</div>
<div class="row">
<div data-template="app:document-nav"/>
</div>
<div class="row">
<div class="col-sm-12" id="maploc"/>
</div>
</div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?language=en"/>
<script type="text/javascript" src="resources/js/gmap3.js"/>
<script type="text/javascript" src="resources/js/url.js"/>
<script type="text/javascript" src="resources/js/map.js"/>
<script type="text/html" id="popupTemplate">
<div class="panel panel-default">
<div class="panel-heading">
<h3 data-content="title"/>
</div>
<div class="panel-body" data-content="content"/>
<div class="panel-footer" data-content="footer"/>
</div>
</script>
</div>
\ No newline at end of file
xquery version "3.0";
module namespace analysis="http://nines.ca/exist/engl434app/analysis";
import module namespace ner="http://exist-db.org/xquery/stanford-ner";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace config="http://nines.ca/exist/engl434app/config" at "config.xqm";
import module namespace collection="http://nines.ca/exist/engl434app/collection" at "collection.xql";
import module namespace document="http://nines.ca/exist/engl434app/document" at "document.xql";
declare namespace tei='http://www.tei-c.org/ns/1.0';
declare function analysis:count-pages($document as node()) as xs:integer {
count($document//tei:pb)
};
declare function analysis:count-paragraphs($document as node()) as xs:integer {
count($document//tei:p)
};
declare function analysis:words-per-paragraph($document as node()) as xs:integer* {
for $p in $document//tei:p
return count(tokenize($p/string(), '\W+'))
};
declare function analysis:distinct-words-per-paragraph($document as node()) as xs:integer* {
for $p in $document//tei:p
return count(distinct-values(tokenize(lower-case($p/string()), '\W+')))
};
declare function analysis:characters-per-paragraph($document as node()) as xs:integer* {
for $p in $document//tei:p
return string-length($p/string())
};
declare function analysis:words($nodes as node()) as xs:string* {
for $node in $nodes
return tokenize(lower-case($node), '\W+')
};
declare function analysis:distinct-words($nodes as node()) as xs:string* {
distinct-values(analysis:words($nodes))
};
declare function analysis:word-list($nodes as node()*) as node()* {
let $words := analysis:words($nodes)
for $w in distinct-values($words)
let $count := count(index-of($words, $w))
order by $count descending
return <word count='{$count}'>{$w}</word>
};
declare function analysis:analyze-document($document) {
<document id="{document:id($document)}">
<title>{document:title($document)}</title>
<pages total="{count($document//tei:pb)}"/>
<paragraphs total="{count($document//tei:p)}">
<words>{analysis:words-per-paragraph($document)}</words>
<distinct-words>{analysis:distinct-words-per-paragraph($document)}</distinct-words>
<characters>{analysis:characters-per-paragraph($document)}</characters>
</paragraphs>
<words total="{count(analysis:words($document))}" unique="{count(analysis:distinct-words($document))}">
{ analysis:word-list($document) }
</words>
<characters total="{string-length($document/string())}"/>
</document>
};
declare function analysis:analyzed-date($id as xs:string) as xs:dateTime? {
xmldb:last-modified($config:analysis-root, $id || '.xml')
};
declare function analysis:fetch($id as xs:string) as node() {
let $document := collection:fetch($id)
let $analyzed-uri := $config:analysis-root || '/' || $id || '.xml'
return
if(doc-available($analyzed-uri) and analysis:analyzed-date($id) > document:modified($document)) then
doc($analyzed-uri)
else
let $analysis := analysis:analyze-document($document)
let $path := xmldb:store($config:analysis-root, $id || '.xml', $analysis)
return $analysis
};
(:~
: This is the api XQuery which will (by default) be called by controller.xql
: to process any URI containing "/api/".
:)
xquery version "3.0";
declare namespace api="http://nines.ca/exist/engl434app/api";
declare namespace tei='http://www.tei-c.org/ns/1.0';
declare namespace xhtml='http://www.w3.org/1999/xhtml';
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace json="http://www.json.org";
declare option output:method "json";
declare option output:media-type "text/javascript";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace config="http://nines.ca/exist/engl434app/config" at "config.xqm";
import module namespace collection="http://nines.ca/exist/engl434app/collection" at "collection.xql";
import module namespace document="http://nines.ca/exist/engl434app/document" at "document.xql";
import module namespace analysis="http://nines.ca/exist/engl434app/analysis" at "analysis.xql";
import module namespace classifier="http://nines.ca/exist/engl434app/classifier" at "classifier.xql";
import module namespace mapping="http://nines.ca/exist/engl434app/mapping" at "mapping.xql";
declare function api:documents() as node()* {
for $document in collection:documents()
return
<document>
<id>{document:id($document)}</id>
<title>{document:title($document)}</title>
<pages>{document:count-pages($document)}</pages>
</document>
};
declare function api:location-names() as node()* {
for $name in
distinct-values(collection($config:classified-root)//tei:rs[@type='location']/string())
return <name>{$name}</name>
};
declare function api:location-cache() as node()* {
let $name := request:get-parameter('loc', ())
return
if(empty($name)) then
()
else
mapping:fetch($name)
};
declare function api:locations() as node()* {
let $id := request:get-parameter('id', ())
return
if(empty($id)) then
()
else
let $names := mapping:fetch-locations($id)
return mapping:fetch($names)
};
declare function api:analyze-entities() {
let $id := request:get-parameter('id', ())
return
if(empty($id)) then
()
else
let $null := if(doc-available($config:classified-root || '/' || $id || '.xml')) then
xmldb:remove($config:classified-root, $id || '.xml')
else
()
let $analyzed := classifier:fetch($id)
return
<document>
<id>{document:id($analyzed)}</id>
<title>{document:title($analyzed)}</title>
<people>{count($analyzed//tei:rs[@type='person'])}</people>
<locations>{count($analyzed//tei:rs[@type='location'])}</locations>
<organizations>{count($analyzed//tei:rs[@type='organization'])}</organizations>
<dates>{count($analyzed//tei:date)}</dates>
<times>{count($analyzed//tei:time)}</times>
</document>
};
declare function api:analyze-document() {
let $id := request:get-parameter('id', ())
return
if(empty($id)) then
()
else
let $null := if(doc-available($config:analysis-root || '/' || $id || '.xml')) then
xmldb:remove($config:analysis-root, $id || '.xml')
else
()
let $analyzed := analysis:fetch($id)
return
<document>
<id>{$id}</id>
<title>{$analyzed//title/string()}</title>
<pages>{$analyzed//pages/@total/string()}</pages>
<paragraphs>{$analyzed//paragraphs/@total/string()}</paragraphs>
<words>{$analyzed//words/@total/string()}</words>
<characters>{$analyzed//characters/@total/string()}</characters>
</document>
};
let $functionName := request:get-attribute('function')
let $function :=
try {
function-lookup(QName("http://nines.ca/exist/engl434app/api", $functionName), 0)
} catch * {
()
}
return
if(exists($function)) then
<root> { $function() } </root>
else
let $null := response:set-status-code(404)
return <error status="404">The API function {$functionName} cannot be found.</error>
\ No newline at end of file
This diff is collapsed.
xquery version "3.0";
module namespace classifier="http://nines.ca/exist/engl434app/classifier";
import module namespace ner="http://exist-db.org/xquery/stanford-ner";
import module namespace console="http://exist-db.org/xquery/console";
import module namespace config="http://nines.ca/exist/engl434app/config" at "config.xqm";
import module namespace collection="http://nines.ca/exist/engl434app/collection" at "collection.xql";
import module namespace document="http://nines.ca/exist/engl434app/document" at "document.xql";
declare namespace tei='http://www.tei-c.org/ns/1.0';
declare default element namespace 'http://www.tei-c.org/ns/1.0';
declare function classifier:node($node as node()) as node() {
ner:classify-node($config:ner-classifier, $node, function($tag, $content) {
let $type := lower-case($tag)
return
switch(lower-case($type))
case 'person' return <rs type='person'>{$content}</rs>
case 'location' return <rs type='location'>{$content}</rs>
case 'organization' return <rs type='organization'>{$content}</rs>
case 'date' return <date>{$content}</date>
case 'time' return <time>{$content}</time>
default return ''
})
};
declare function classifier:nodes($nodes as node()*) as node()* {
for $node at $p in $nodes
return
if(not($node instance of element())) then
$node
else
try {
classifier:node($node)
} catch * {
let $null := console:log(string-join(($err:code , $err:description, $err:value), " : "))
return $node
}
};
(: return a deep copy of the element and all sub elements :)
declare function local:copy($element as element()) as element() {
element {node-name($element)}
{$element/@*,
for $child in $element/node()
return
if ($child instance of element())
then local:copy($child)
else $child
}
};