def test_getpassage(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 passage = text.getTextualNode(subreference="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" }) self.assertIsInstance(passage, CtsPassage) self.assertEqual(str(passage.urn), "urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1") self.assertEqual( passage.xml.findall(".//{http://www.tei-c.org/ns/1.0}l[@n='1']") [0].text, "Hic est quem legis ille, quem requiris, ") # Test without reference passage = text.getTextualNode() requests.assert_called_with( "http://services.perseids.org/remote/cts", params={ "request": "GetPassage", "urn": "urn:cts:latinLit:phi1294.phi002.perseus-lat2" })
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=Reference("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" })
def test_init_without_citation(self, requests): text = CtsText("urn:cts:latinLit:phi1294.phi002.perseus-lat2", retriever=self.endpoint) requests.return_value.text = GET_PASSAGE # Test with -1 text.getTextualNode(subreference="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" }) self.assertEqual(text.citation.name, "book")
def test_get_siblings(self): self.endpoint.getPassage = mock.MagicMock(return_value=GET_PASSAGE) self.endpoint.getPrevNextUrn = mock.MagicMock(return_value=NEXT_PREV) self.endpoint.getFirstUrn = mock.MagicMock(return_value=Get_FIRST) self.endpoint.getValidReff = mock.MagicMock( return_value=GET_VALID_REFF_1_1) text = CtsText(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2", retriever=self.endpoint) passage = text.getTextualNode("1.1") self.assertEqual(passage.siblingsId, ("1.pr", "1.2"), "SiblingsId should resolve") # When next does not exist from the original resource self.endpoint.getPrevNextUrn.assert_called_with( urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
def getTextualNode(self, textId, subreference=None, prevnext=False, metadata=False): """ Retrieve a text node from the API :param textId: CtsTextMetadata Identifier :type textId: str :param subreference: CapitainsCtsPassage Reference :type subreference: str :param prevnext: Retrieve graph representing previous and next passage :type prevnext: boolean :param metadata: Retrieve metadata about the passage and the text :type metadata: boolean :return: CapitainsCtsPassage :rtype: CapitainsCtsPassage """ text = CtsText(urn=textId, retriever=self.endpoint) if metadata or prevnext: return text.getPassagePlus(reference=subreference) else: return text.getTextualNode(subreference=subreference)
retriever = HttpCtsRetriever("http://cts.dh.uni-leipzig.de/api/cts") # Given that we have other examples that shows how to work with text, # we will focus here on playing with the graph functionality of texts implementations. # We are gonna retrieve a text passage and the retrieve all its siblings in different fashion# # The main point is to find all children of the same parent. # The use case could be the following : some one want to retrieve the full text around a citation # To enhance the display a little. # We will work with the line 7 of poem 39 of book 4 of Martial's Epigrammata # The text is urn:cts:latinLit:phi1294.phi002.perseus-lat2 text = CtsText(retriever=retriever, urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2") # We retrieve up the passage target = text.getTextualNode(subreference="4.39.7") print(target.text) """ Nec quae Callaico linuntur auro, """ # The parent way : # - get to the parent, # - retrieve each node, # - print only the one which are not target parent = target.parent for node in parent.children: if node.id != target.id: print("{}\t{}".format(node.id, node.text)) else: