Esempio n. 1
0
    def test_getReffs_full(self):
        """ Ensure getReffs works well """
        reffs = self.resolver.getReffs(textId="urn:cts:latinLit:phi1294.phi002.perseus-lat2", level=1)
        self.assertEqual(
            len(reffs), 14,
            "There should be 14 books"
        )
        self.assertEqual(
            reffs[0], CtsReference("1")
        )

        reffs = self.resolver.getReffs(textId="urn:cts:latinLit:phi1294.phi002.perseus-lat2", level=2)
        self.assertEqual(
            len(reffs), 1527,
            "There should be 1527 poems"
        )
        self.assertEqual(
            reffs[0], CtsReference("1.pr")
        )

        reffs = self.resolver.getReffs(
            textId="urn:cts:latinLit:phi1294.phi002.perseus-lat2",
            subreference="1.1",
            level=1
        )
        self.assertEqual(
            len(reffs), 6,
            "There should be 6 references"
        )
        self.assertEqual(
            reffs[0], CtsReference("1.1.1")
        )
Esempio n. 2
0
 def test_getSiblings(self):
     """ Ensure getSiblings works well """
     previous, nextious = self.resolver.getSiblings(
         textId="urn:cts:latinLit:phi1294.phi002.perseus-lat2", subreference="1.1"
     )
     self.assertEqual(
         previous, CtsReference("1.pr"),
         "Previous reference should be well computed"
     )
     self.assertEqual(
         nextious, CtsReference("1.2"),
         "Next reference should be well computed"
     )
Esempio n. 3
0
    def test_getPassage_prevnext(self):
        """ Test that we can get a full text with its metadata"""
        passage = self.resolver.getTextualNode(
            "urn:cts:latinLit:phi1294.phi002.perseus-lat2", subreference="1.1",  metadata=True
        )

        self.assertIsInstance(
            passage, PrototypeCtsPassage,
            "GetPassage should always return passages objects"
        )
        self.assertEqual(
            passage.prevId, CtsReference("1.pr"),
            "Previous CapitainsCtsPassage ID should be parsed"
        )
        self.assertEqual(
            passage.nextId, CtsReference("1.2"),
            "Next CapitainsCtsPassage ID should be parsed"
        )

        children = list(passage.getReffs())
        # Ensure navigability
        self.assertIn(
            "verentia ludant; quae adeo antiquis auctoribus defuit, ut",
            passage.prev.export(output=Mimetypes.PLAINTEXT),
            "Left and Right Navigation should be available"
        )
        self.assertIn(
            "Qui tecum cupis esse meos ubicumque libellos ",
            passage.next.export(output=Mimetypes.PLAINTEXT),
            "Left and Right Navigation should be available"
        )

        # We check the passage is able to perform further requests and is well instantiated
        self.assertEqual(
            str(children[0]), '1.1.1',
            "Resource should be string identifiers"
        )

        self.assertIn(
            "Hic est quem legis ille, quem requiris,", passage.export(output=Mimetypes.PLAINTEXT),
            "Export CtsTextMetadata should work correctly"
        )

        self.assertEqual(
            passage.export(output=Mimetypes.PYTHON.ETREE).xpath(".//tei:l[@n='1']/text()", namespaces=XPATH_NAMESPACES, magic_string=False),
            ["Hic est quem legis ille, quem requiris, "],
            "Export to Etree should give an Etree or Etree like object"
        )
Esempio n. 4
0
    def test_getPassage_full(self):
        """ Test that we can get a full text """
        passage = self.resolver.getTextualNode("urn:cts:latinLit:phi1294.phi002.perseus-lat2")
        self.assertIsInstance(
            passage, PrototypeCtsPassage,
            "GetPassage should always return passages objects"
        )

        children = passage.getReffs()

        # We check the passage is able to perform further requests and is well instantiated
        self.assertEqual(
            children[0], CtsReference('1'),
            "Resource should be string identifiers"
        )

        self.assertIn(
            "Hic est quem legis ille, quem requiris,", passage.export(output=Mimetypes.PLAINTEXT),
            "Export CtsTextMetadata should work correctly"
        )

        self.assertEqual(
            passage.export(
                output=Mimetypes.PYTHON.ETREE
            ).xpath(
                ".//tei:div[@n='1']/tei:div[@n='1']/tei:l[@n='1']/text()", namespaces=XPATH_NAMESPACES, magic_string=False
            ),
            ["Hic est quem legis ille, quem requiris, "],
            "Export to Etree should give an Etree or Etree like object"
        )
Esempio n. 5
0
    def test_getpassage_variabletypes(self, requests):
        text = CtsText("urn:cts:latinLit:phi1294.phi002.perseus-lat2", self.endpoint, citation=self.citation)
        requests.return_value.text = GET_PASSAGE

        # Test with -1
        _ = text.getTextualNode(subreference=CtsReference("1.1"))
        requests.assert_called_with(
            "http://services.perseids.org/remote/cts",
            params={
                "request": "GetPassage",
                "urn": "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1"
            }
        )
        # Test with -1
        _ = text.getTextualNode(subreference=URN("urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.2"))
        requests.assert_called_with(
            "http://services.perseids.org/remote/cts",
            params={
                "request": "GetPassage",
                "urn": "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.2"
            }
        )
        # Test with -1
        _ = text.getTextualNode(subreference=["1", "1", "1"])
        requests.assert_called_with(
            "http://services.perseids.org/remote/cts",
            params={
                "request": "GetPassage",
                "urn": "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1.1"
            }
        )
Esempio n. 6
0
    def test_getPassage_full_metadata(self):
        """ Test that we can get a full text with its metadata"""
        passage = self.resolver.getTextualNode("urn:cts:latinLit:phi1294.phi002.perseus-lat2", metadata=True)

        self.assertIsInstance(
            passage, PrototypeCtsPassage,
            "GetPassage should always return passages objects"
        )
        self.assertEqual(
            str(passage.metadata[RDF_NAMESPACES.CTS.term("title"), "eng"]), "Epigrammata",
            "Local Inventory Files should be parsed and aggregated correctly"
        )
        self.assertEqual(
            str(passage.metadata[RDF_NAMESPACES.CTS.term("groupname"), "eng"]), "Martial",
            "Local Inventory Files should be parsed and aggregated correctly"
        )
        self.assertEqual(
            str(passage.metadata[RDF_NAMESPACES.CTS.term("label"), "eng"]), "Epigrams",
            "Local Inventory Files should be parsed and aggregated correctly"
        )
        self.assertEqual(
            str(passage.metadata[RDF_NAMESPACES.CTS.term("description"), "eng"]),
            "M. Valerii Martialis Epigrammaton libri / recognovit W. Heraeus",
            "Local Inventory Files should be parsed and aggregated correctly"
        )
        self.assertEqual(
            passage.citation.name, "book",
            "Local Inventory Files should be parsed and aggregated correctly"
        )
        self.assertEqual(
            len(passage.citation), 3,
            "Local Inventory Files should be parsed and aggregated correctly"
        )

        children = list(passage.getReffs(level=3))
        # We check the passage is able to perform further requests and is well instantiated
        self.assertEqual(
            children[0], CtsReference('1.pr.1'),
            "Resource should be string identifiers"
        )

        self.assertIn(
            "Hic est quem legis ille, quem requiris,", passage.export(output=Mimetypes.PLAINTEXT),
            "Export CtsTextMetadata should work correctly"
        )

        self.assertEqual(
            passage.export(
                output=Mimetypes.PYTHON.ETREE
            ).xpath(
                ".//tei:div[@n='1']/tei:div[@n='1']/tei:l[@n='1']/text()", namespaces=XPATH_NAMESPACES, magic_string=False
            ),
            ["Hic est quem legis ille, quem requiris, "],
            "Export to Etree should give an Etree or Etree like object"
        )
Esempio n. 7
0
 def test_getSiblings_prevOnly(self):
     """ Ensure getSiblings works well when there is only the previous passage"""
     previous, nextious = self.resolver.getSiblings(
         textId="urn:cts:latinLit:phi1294.phi002.perseus-lat2", subreference="14.223"
     )
     self.assertEqual(
         previous, CtsReference("14.222"),
         "Previous reference should be well computed"
     )
     self.assertEqual(
         nextious, None,
         "Next reference should not exist"
     )
Esempio n. 8
0
 def test_text_resource(self):
     """ Test to get the text resource to perform other queries """
     Repository = CtsCapitainsLocalResolver(["./tests/testing_data/farsiLit"])
     text, metadata = Repository.__getText__("urn:cts:farsiLit:hafez.divan.perseus-eng1")
     self.assertEqual(
         len(text.citation), 4,
         "Object has a citation property of length 4"
     )
     self.assertEqual(
         text.getTextualNode(CtsReference("1.1.1.1")).export(output=Mimetypes.PLAINTEXT),
         "Ho ! Saki, pass around and offer the bowl (of love for God) : ### ",
         "It should be possible to retrieve text"
     )
Esempio n. 9
0
    def test_ingest_multiple(self):
        b = xmlparser("""
<tei:tei xmlns:tei="http://www.tei-c.org/ns/1.0">
<tei:cRefPattern n="line"
             matchPattern="(\\w+).(\\w+).(\\w+)"
             replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1' and @type='section']/tei:div[@n='$2']/tei:l[@n='$3'])">
    <tei:p>This pointer pattern extracts line</tei:p>
</tei:cRefPattern>
<tei:cRefPattern n="poem"
             matchPattern="(\\w+).(\\w+)"
             replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1']/tei:div[@n='$2'])">
    <tei:p>This pointer pattern extracts poem</tei:p>
</tei:cRefPattern>
<tei:cRefPattern n="book"
             matchPattern="(\\w+)"
             replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1'])">
    <tei:p>This pointer pattern extracts book</tei:p>
</tei:cRefPattern>
</tei:tei>
""".replace("\n", "").replace("\s+", " "))

        a = Citation.ingest(b)

        self.assertEqual(
            a.export(Mimetypes.XML.TEI),
            """<tei:cRefPattern n="book" matchPattern="(\\w+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n=\'$1\'])"><tei:p>This pointer pattern extracts book</tei:p></tei:cRefPattern>"""
        )
        self.assertEqual(
            a.child.export(Mimetypes.XML.TEI),
            """<tei:cRefPattern n="poem" matchPattern="(\\w+)\.(\\w+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n=\'$1\']/tei:div[@n=\'$2\'])"><tei:p>This pointer pattern extracts poem</tei:p></tei:cRefPattern>"""
        )
        self.assertEqual(
            a.child.child.export(Mimetypes.XML.TEI),
            """<tei:cRefPattern n="line" matchPattern="(\\w+)\.(\\w+)\.(\\w+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n=\'$1\' and @type=\'section\']/tei:div[@n=\'$2\']/tei:l[@n=\'$3\'])"><tei:p>This pointer pattern extracts line</tei:p></tei:cRefPattern>"""
        )
        self.assertEqual(
            a.child.child.fill(CtsReference("1.2.3")),
            "/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n=\'1\' and @type=\'section\']/tei:div[@n=\'2\']/tei:l[@n=\'3\']"
        )
Esempio n. 10
0
    def getReffs(self, textId, level=1, subreference=None):
        """ Retrieve the siblings of a textual node

        :param textId: CtsTextMetadata Identifier
        :type textId: str
        :param level: Depth for retrieval
        :type level: int
        :param subreference: CapitainsCtsPassage Reference
        :type subreference: str
        :return: List of references
        :rtype: [str]
        """
        depth = level
        if subreference:
            textId = "{}:{}".format(textId, subreference)
        if subreference:
            if isinstance(subreference, CtsReference):
                depth += subreference.depth
            else:
                depth += (CtsReference(subreference)).depth
        if level:
            level = max(depth, level)
        return self.getValidReff(urn=textId, level=level)
Esempio n. 11
0
    def test_getvalidreff(self, requests):
        text = CtsText("urn:cts:latinLit:phi1294.phi002.perseus-lat2", self.endpoint, citation=self.citation)
        requests.return_value.text = GET_VALID_REFF

        # Test with -1
        text.getValidReff(level=-1)
        requests.assert_called_with(
            "http://services.perseids.org/remote/cts",
            params={
                "request": "GetValidReff",
                "urn": "urn:cts:latinLit:phi1294.phi002.perseus-lat2",
                "level": "3"
            }
        )

        # Test with level 2
        text.getValidReff(level=2)
        requests.assert_called_with(
            "http://services.perseids.org/remote/cts",
            params={
                "request": "GetValidReff",
                "urn": "urn:cts:latinLit:phi1294.phi002.perseus-lat2",
                "level": "2"
            }
        )

        # Test with no level
        text.getValidReff()
        requests.assert_called_with(
            "http://services.perseids.org/remote/cts",
            params={
                "request": "GetValidReff",
                "urn": "urn:cts:latinLit:phi1294.phi002.perseus-lat2",
                "level": "1"
            }
        )

        # Test with a ref as str
        text.getValidReff(reference="1.pr")
        requests.assert_called_with(
            "http://services.perseids.org/remote/cts",
            params={
                "request": "GetValidReff",
                "urn": "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.pr",
                "level": "1"
            }
        )

        # Test with a ref as subreference
        reffs = text.getValidReff(reference=CtsReference("1.pr"))
        requests.assert_called_with(
            "http://services.perseids.org/remote/cts",
            params={
                "request": "GetValidReff",
                "urn": "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.pr",
                "level": "1"
            }
        )

        # Test the parsing
        self.assertEqual(reffs[0], "1.pr.1")