def test_get_siblings(self): """ Test first passage """ app = Flask("Nemo") nemo = Nemo(app=app, base_url="", resolver=NautilusDummy, original_breadcrumb=False, chunker={ "default": lambda x, y: level_grouper(x, y, groupby=20) }) # First range p = nemo.get_passage("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.pr.1-1.pr.20") l, r = nemo.get_siblings( "urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.pr.1-1.pr.20", p) self.assertEqual(l, None, "There should be nothing on the left") self.assertEqual(r, "1.pr.21-1.pr.22", "Next passage should not be 20 long") # Second range p = nemo.get_passage("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.pr.21-1.pr.22") l, r = nemo.get_siblings( "urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.pr.21-1.pr.22", p) self.assertEqual(l, "1.pr.1-1.pr.20", "There should be something on the left") self.assertEqual(r, "1.1.1-1.1.6", "Next passage should not be 20 long") # Last range p = nemo.get_passage("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "14.223.1-14.223.2") l, r = nemo.get_siblings( "urn:cts:latinLit:phi1294.phi002.perseus-lat2", "14.223.1-14.223.2", p) self.assertEqual(l, "14.222.1-14.222.2", "Previous passage does not have to be 20 long") self.assertEqual(r, None, "There should be nothing on the right") # Passage with unknown range p = nemo.get_passage("urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.11.1-1.11.2") l, r = nemo.get_siblings( "urn:cts:latinLit:phi1294.phi002.perseus-lat2", "1.11.1-1.11.2", p) self.assertEqual( l, "1.10.3-1.10.4", "Passage should be computed specifically if texts have unknown range" ) self.assertEqual( r, "1.11.3-1.11.4", "Passage should be computed specifically if texts have unknown range" )
def test_flask_nemo(self): """ Testing Flask Nemo is set up""" a = Nemo() self.assertIsInstance(a, Nemo) a = Nemo()
nemo = Nemo( # API URL is the URL of your endpoint. api_url="http://services2.perseids.org/exist/restxq/cts", # We set up the base url to be empty. If you want nemo to be on a # subpath called "cts", you would have # base_url="cts", base_url="", name="nemo", # In our case, we have an inventory named "nemo" inventory="nemo", css=[ # USE Own CSS Files "static/tei.pb.min.css", "static/ciham.css" ], js=[ # use own js file to load a script to go from normalized edition to diplomatic one. "static/ciham.js" ], transform={ "urn:cts:froLit:jns915.jns1856.ciham-fro1": "static/ciham.xslt" }, # We give thee ap object #app=app chunker={ # The default chunker takes care of book, poem, lines # but it would be cool to have 30 lines group for Nemo "urn:cts:latinLit:phi0959.phi005.perseus-lat2": lambda version, callback: Nemo.line_chunker( version, callback, lines=30), "urn:cts:froLit:jns915.jns1856.ciham-fro1": lambda text, getLevel: [(reff.split(":")[-1], reff.split(":")[-1]) for reff in getLevel(1)], "urn:cts:latinLit:phi0472.phi001.perseus-lat2": lambda text, getLevel: [(reff.split(":")[-1], reff.split(":")[-1]) for reff in getLevel(1)], "urn:cts:latinLit:phi1212.phi002.perseus-lat1": lambda version, callback: Nemo. line_chunker(version, callback, lines=5 ), #Apuleius, Metamorphoses, 5 sections at a time "default": Nemo.level_grouper # lambda text, cb: Nemo.line_grouper(text, cb, 50), }, templates={"passage_footer": "templates/passage_footer.html"})
app = Flask("Nautilus") nautilus_cache = RedisCache("redis", port=6379, default_timeout=0) nautilus = FlaskNautilus(app=app, prefix="/api/cts", name="nautilus", resources=[ os.path.join(d, o) for o in os.listdir(d) if os.path.isdir(os.path.join(d, o)) ], parser_cache=WerkzeugCacheWrapper(nautilus_cache), http_cache=Cache(config={'CACHE_TYPE': "simple"})) # We set up Nemo nemo = Nemo(app=app, name="nemo", base_url="", api_url="/api/cts", retriever=nautilus.retriever, chunker={"default": Nemo.level_grouper}, css=["/opt/static/assets/nemo.secondary/css/theme-ext.css"], transform={"default": "/opt/static/assets/xslt/epidocShort.xsl"}, templates={"passage_footer": "templates/passage_footer.html"}) # We register its routes nemo.register_routes() # We register its filters nemo.register_filters() app.debug = True if __name__ == "__main__": app.run(debug=True, host='0.0.0.0')
d = "/opt/data" app = Flask("Nautilus") nautilus_cache = FileSystemCache("/opt/cache") nautilus = FlaskNautilus( app=app, prefix="/api/cts", name="nautilus", resources=[os.path.join(d,o) for o in os.listdir(d) if os.path.isdir(os.path.join(d,o))], parser_cache=WerkzeugCacheWrapper(nautilus_cache), http_cache=Cache(config={'CACHE_TYPE': "simple"}) ) # We set up Nemo nemo = Nemo( app=app, name="nemo", base_url="", api_url="/api/cts", retriever=nautilus.retriever, **nemo_config ) # We register its routes nemo.register_routes() # We register its filters nemo.register_filters() app.debug = True if __name__ == "__main__": app.run(debug=True, host='0.0.0.0')