Example #1
0
    def test_or_in_xpath(self):
        """ Test that the xpath and scope generation accepts or xpath expression in form of "|" or " or "
        """
        a = Citation(
            name="line",
            refsDecl=
            "/TEI/text/body/div/div[@n=\"$1\"]/*[self::tei:l or self::tei:p][@n=\"$2\"]"
        )
        b = Citation(
            name="line",
            refsDecl=
            "/TEI/text/body/div/div[@n=\"$1\"]/*[self::tei:l or self::tei:p][@n=\"$2\"]"
        )
        c = Citation(
            name="line",
            refsDecl=
            "/TEI/text/body/div/*[self::tei:l or self::tei:p][@n=\"$1\"]")
        self.assertEqual(a.scope, "/TEI/text/body/div/div[@n=\"?\"]")
        self.assertEqual(a.xpath, "/*[self::tei:l or self::tei:p][@n=\"?\"]")
        self.assertEqual(
            a.fill(["1", "2"], xpath=False),
            "/TEI/text/body/div/div[@n='1']/*[self::tei:l or self::tei:p][@n='2']"
        )

        self.assertEqual(b.scope, "/TEI/text/body/div/div[@n=\"?\"]")
        self.assertEqual(b.xpath, "/*[self::tei:l or self::tei:p][@n=\"?\"]")

        self.assertEqual(c.scope, "/TEI/text/body/div")
        self.assertEqual(c.xpath, "/*[self::tei:l or self::tei:p][@n=\"?\"]")
Example #2
0
 def testCitationSetters(self):
     d = Citation()
     c = Citation(
         name="ahah",
         refsDecl="/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1']",
         child=None)
     b = Citation(
         name="ahah",
         refsDecl="/tei:TEI/tei:text/tei:body/tei:div/tei:z[@n='$1']",
         child=None)
     with open("tests/testing_data/texts/sample.xml", "rb") as sample:
         a = CapitainsCtsText(resource=sample, citation=b)
     """ Test original setting """
     self.assertIs(a.citation, b)
     """ Test simple replacement """
     a.citation = d
     self.assertIs(a.citation, d)
     """ Test conversion """
     a.citation = c
     self.assertEqual(a.citation.name, "ahah")
     self.assertEqual(a.citation.child, None)
     self.assertEqual(
         a.citation.refsDecl,
         "/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1']")
     self.assertEqual(a.citation.scope,
                      "/tei:TEI/tei:text/tei:body/tei:div")
     self.assertEqual(a.citation.xpath, "/tei:div[@n='?']")
Example #3
0
 def test_child(self):
     c = Citation(
         name="line"
     )
     b = Citation(
         name="poem",
         child=c
     )
     self.assertEqual(b.child, c)
Example #4
0
 def test_fill(self):
     c = Citation(
         name="line",
         scope="/TEI/text/body/div/div[@n=\"?\"]",
         xpath="//l[@n=\"?\"]"
     )
     self.assertEqual(c.fill(Reference("1.2")), "/TEI/text/body/div/div[@n='1']//l[@n='2']")
     self.assertEqual(c.fill(Reference("1.1")), "/TEI/text/body/div/div[@n='1']//l[@n='1']")
     self.assertEqual(c.fill("1", xpath=True), "//l[@n='1']")
     self.assertEqual(c.fill("2", xpath=True), "//l[@n='2']")
     self.assertEqual(c.fill(None, xpath=True), "//l[@n]")
     self.assertEqual(c.fill([None, None]), "/TEI/text/body/div/div[@n]//l[@n]")
Example #5
0
 def test_iter(self):
     c = Citation(
         name="line"
     )
     b = Citation(
         name="poem",
         child=c
     )
     a = Citation(
         name="book",
         child=b
     )
     self.assertEqual([e for e in a], [a, b, c])
Example #6
0
 def test_len(self):
     c = Citation(
         name="line"
     )
     b = Citation(
         name="poem",
         child=c
     )
     a = Citation(
         name="book",
         child=b
     )
     self.assertEqual(len(a), 3)
Example #7
0
 def setUp(self):
     a = Citation(name="line")
     b = Citation(name="poem", child=a)
     self.citation = Citation(name="book", child=b)
     self.url = "http://services.perseids.org/remote/cts"
     self.endpoint = HttpCtsRetriever(self.url)
     self.endpoint.getPassage = mock.MagicMock(return_value=GET_PASSAGE)
     self.endpoint.getPrevNextUrn = mock.MagicMock(return_value=NEXT_PREV)
     self.endpoint.getValidReff = mock.MagicMock(
         return_value=GET_VALID_REFF)
     self.endpoint.getFirstUrn = mock.MagicMock(return_value=Get_FIRST)
     self.text = CtsText("urn:cts:latinLit:phi1294.phi002.perseus-lat2",
                         self.endpoint,
                         citation=self.citation)
Example #8
0
 def test_updateRefsdecl(self):
     c = Citation(
         name="line",
         scope="/TEI/text/body/div/div[@n=\"?\"]",
         xpath="//l[@n=\"?\"]"
     )
     self.assertEqual(c.refsDecl, "/TEI/text/body/div/div[@n=\"$1\"]//l[@n=\"$2\"]")
Example #9
0
 def test_updateScopeXpath(self):
     c = Citation(
         name="line",
         refsDecl="/TEI/text/body/div/div[@n=\"$1\"]//l[@n=\"$2\"]"
     )
     self.assertEqual(c.scope, "/TEI/text/body/div/div[@n=\"?\"]")
     self.assertEqual(c.xpath, "//l[@n=\"?\"]")
Example #10
0
 def test_get_item(self):
     c = Citation(
         name="line"
     )
     b = Citation(
         name="poem",
         child=c
     )
     a = Citation(
         name="book",
         child=b
     )
     self.assertEqual(a[-1], c, "Last citation is C")
     self.assertEqual(a[2], c, "Third citation is C")
     self.assertEqual(a[0], a, "First citation is A")
     self.assertEqual(a[1], b, "Second citation is B")
     with self.assertRaises(KeyError, msg="XmlCtsCitation is out of bound"):
         a[8]
Example #11
0
 def __findCRefPattern(self, xml):
     """ Find CRefPattern in the text and set object.citation
     :param xml: Xml Resource
     :type xml: lxml.etree._Element
     :return: None
     """
     if self.citation.isEmpty():
         citation = xml.xpath("//tei:refsDecl[@n='CTS']", namespaces=NS),
         if len(citation):
             self.citation = Citation.ingest(resource=citation[0], xpath=".//tei:cRefPattern")
Example #12
0
 def test_updateRefsdecl_and(self):
     c = Citation(
         name="line",
         refsDecl=
         "/TEI/text/body/div/div[@n=\"?\" and @subtype='edition']/l[@n=\"?\"]"
     )
     self.assertEqual(
         c.refsDecl,
         "/TEI/text/body/div/div[@n=\"?\" and @subtype='edition']/l[@n=\"?\"]"
     )
Example #13
0
 def test_fill(self):
     c = Citation(name="line",
                  scope="/TEI/text/body/div/div[@n=\"?\"]",
                  xpath="//l[@n=\"?\"]")
     self.assertEqual(c.fill(Reference("1.2")),
                      "/TEI/text/body/div/div[@n='1']//l[@n='2']")
     self.assertEqual(c.fill(Reference("1.1")),
                      "/TEI/text/body/div/div[@n='1']//l[@n='1']")
     self.assertEqual(c.fill(None), "/TEI/text/body/div/div[@n]//l[@n]")
     self.assertEqual(c.fill("1", xpath=True), "//l[@n='1']")
     self.assertEqual(c.fill("2", xpath=True), "//l[@n='2']")
     self.assertEqual(c.fill(None, xpath=True), "//l[@n]")
     self.assertEqual(c.fill([None, None]),
                      "/TEI/text/body/div/div[@n]//l[@n]")
     self.assertEqual(c.fill(["1", None]),
                      "/TEI/text/body/div/div[@n='1']//l[@n]")
Example #14
0
 def setUp(self):
     a = Citation(
         name="line",
         refsDecl=
         "/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1' and @type='section']/tei:div[@n='$2']/tei:l[@n='$3']"
     )
     b = Citation(
         name="poem",
         child=a,
         refsDecl=
         "/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1' and @type='section']/tei:div[@n='$2']"
     )
     self.citation = Citation(
         name="book",
         child=b,
         refsDecl=
         "/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1' and @type='section']"
     )
     self.endpoint = HttpCtsRetriever(
         "http://services.perseids.org/remote/cts")
Example #15
0
 def __findCRefPattern(self, xml):
     """ Find CRefPattern in the text and set object.citation
     :param xml: Xml Resource
     :type xml: lxml.etree._Element
     :return: None
     """
     if self.citation.isEmpty():
         citation = xml.xpath("//tei:refsDecl[@n='CTS']", namespaces=XPATH_NAMESPACES)
         if len(citation):
             self.citation = Citation.ingest(resource=citation[0], xpath=".//tei:cRefPattern")
         else:
             raise MissingRefsDecl("No reference declaration (refsDecl) found.")
Example #16
0
 def test_str(self):
     a = Citation(name="book",
                  xpath="/tei:div[@n=\"?\"]",
                  scope="/tei:TEI/tei:body/tei:text/tei:div")
     self.assertEqual(
         a.export(Mimetypes.XML.TEI),
         "<tei:cRefPattern n=\"book\" matchPattern=\"(\\w+)\" replacementPattern=\"#xpath(/tei:TEI/tei:body/tei:text/tei:div/tei:div[@n=\"$1\"])\"><tei:p>This pointer pattern extracts book</tei:p></tei:cRefPattern>"
     )
     b = Citation(
         name="chapter",
         xpath="/tei:div[@n=\"?\"]",
         scope="/tei:TEI/tei:body/tei:text/tei:div/tei:div[@n=\"?\"]")
     self.assertEqual(
         b.export(Mimetypes.XML.TEI),
         "<tei:cRefPattern n=\"chapter\" matchPattern=\"(\\w+)\.(\\w+)\" replacementPattern=\"#xpath(/tei:TEI/tei:body/tei:text/tei:div/tei:div[@n=\"$1\"]/tei:div[@n=\"$2\"])\"><tei:p>This pointer pattern extracts chapter</tei:p></tei:cRefPattern>"
     )
     a = Citation()
     self.assertEqual(a.export(Mimetypes.XML.TEI), "")
Example #17
0
    def test_ingest_single_and(self):
        text = xmlparser("""
<tei:tei xmlns:tei="http://www.tei-c.org/ns/1.0">
    <tei:cRefPattern n="section" matchPattern="(.+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:div[@n='$1' and @type='section'])" />
</tei:tei>
""".replace("\n", "").replace("\s+", " "))
        citation = Citation.ingest(text)
        self.maxDiff = None
        self.assertEqual(
            str(citation),
            """<tei:cRefPattern n="section" matchPattern="(\\w+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:div[@n=\'$1\' and @type='section'])"><tei:p>This pointer pattern extracts section</tei:p></tei:cRefPattern>"""
        )
        self.assertEqual(citation.scope, "/tei:TEI/tei:text/tei:body/tei:div[@type='edition']")
        self.assertEqual(citation.xpath, "/tei:div[@n='?' and @type='section']")
        self.assertEqual(citation.fill("1"), "/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:div[@n=\'1\' and @type='section']")
Example #18
0
    def test_or_in_xpath(self):
        """ Test that the xpath and scope generation accepts or xpath expression in form of "|" or " or "
        """
        a = Citation(
            name="line",
            refsDecl="/TEI/text/body/div/div[@n=\"$1\"]/*[self::tei:l or self::tei:p][@n=\"$2\"]"
        )
        b = Citation(
            name="line",
            refsDecl="/TEI/text/body/div/div[@n=\"$1\"]/*[self::tei:l or self::tei:p][@n=\"$2\"]"
        )
        c = Citation(
            name="line",
            refsDecl="/TEI/text/body/div/*[self::tei:l or self::tei:p][@n=\"$1\"]"
        )
        self.assertEqual(a.scope, "/TEI/text/body/div/div[@n=\"?\"]")
        self.assertEqual(a.xpath, "/*[self::tei:l or self::tei:p][@n=\"?\"]")
        self.assertEqual(a.fill(["1", "2"], xpath=False), "/TEI/text/body/div/div[@n='1']/*[self::tei:l or self::tei:p][@n='2']")

        self.assertEqual(b.scope, "/TEI/text/body/div/div[@n=\"?\"]")
        self.assertEqual(b.xpath, "/*[self::tei:l or self::tei:p][@n=\"?\"]")

        self.assertEqual(c.scope, "/TEI/text/body/div")
        self.assertEqual(c.xpath, "/*[self::tei:l or self::tei:p][@n=\"?\"]")
Example #19
0
    def test_ingest_single(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']/tei:div[@n='$2']/tei:l[@n='$3'])">
    <tei:p>This pointer pattern extracts book and poem and line</tei:p>
</tei:cRefPattern>
</tei:tei>
""".replace("\n", "").replace("\s+", " "))
        a = Citation.ingest(b)

        self.assertEqual(
            str(a),
            """<tei:cRefPattern n="line" matchPattern="(\\w+)\.(\\w+)\.(\\w+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n=\'$1\']/tei:div[@n=\'$2\']/tei:l[@n=\'$3\'])"><tei:p>This pointer pattern extracts line</tei:p></tei:cRefPattern>"""
        )
Example #20
0
    def test_ingest_single(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']/tei:div[@n='$2']/tei:l[@n='$3'])">
    <tei:p>This pointer pattern extracts book and poem and line</tei:p>
</tei:cRefPattern>
</tei:tei>
""".replace("\n", "").replace("\s+", " "))
        a = Citation.ingest(b)

        self.assertEqual(
            a.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\']/tei:div[@n=\'$2\']/tei:l[@n=\'$3\'])"><tei:p>This pointer pattern extracts line</tei:p></tei:cRefPattern>"""
        )
Example #21
0
    def test_ingest_single_and(self):
        text = xmlparser("""
<tei:tei xmlns:tei="http://www.tei-c.org/ns/1.0">
    <tei:cRefPattern n="section" matchPattern="(.+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:div[@n='$1' and @type='section'])" />
</tei:tei>
""".replace("\n", "").replace("\s+", " "))
        citation = Citation.ingest(text)
        self.maxDiff = None
        self.assertEqual(
            citation.export(Mimetypes.XML.TEI),
            """<tei:cRefPattern n="section" matchPattern="(\\w+)" replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:div[@n=\'$1\' and @type='section'])"><tei:p>This pointer pattern extracts section</tei:p></tei:cRefPattern>"""
        )
        self.assertEqual(
            citation.scope,
            "/tei:TEI/tei:text/tei:body/tei:div[@type='edition']")
        self.assertEqual(citation.xpath,
                         "/tei:div[@n='?' and @type='section']")
        self.assertEqual(
            citation.fill("1"),
            "/tei:TEI/tei:text/tei:body/tei:div[@type='edition']/tei:div[@n=\'1\' and @type='section']"
        )
Example #22
0
    def test_ingest_and_match(self):
        """ Ensure matching and parsing XML works correctly """
        xml = xmlparser("""<TEI xmlns="http://www.tei-c.org/ns/1.0">
         <refsDecl n="CTS">
            <cRefPattern n="line"
                         matchPattern="(\w+).(\w+).(\w+)"
                         replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1']/tei:div[@n='$2']/tei:l[@n='$3'])">
                <p>This pointer pattern extracts book and poem and line</p>
            </cRefPattern>
            <cRefPattern n="poem"
                         matchPattern="(\w+).(\w+)"
                         replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1']/tei:div[@n='$2'])">
                <p>This pointer pattern extracts book and poem</p>
            </cRefPattern>
            <cRefPattern n="book"
                         matchPattern="(\w+)"
                         replacementPattern="#xpath(/tei:TEI/tei:text/tei:body/tei:div/tei:div[@n='$1'])">
                <p>This pointer pattern extracts book</p>
            </cRefPattern>
        </refsDecl>
        </TEI>""")
        citation = Citation.ingest(xml)
        # The citation that should be returned is the root
        self.assertEqual(citation.name, "book", "Name should have been parsed")
        self.assertEqual(citation.child.name, "poem", "Name of child should have been parsed")
        self.assertEqual(citation.child.child.name, "line", "Name of descendants should have been parsed")

        self.assertEqual(citation.is_root(), True, "Root should be true on root")
        self.assertEqual(citation.match("1.2"), citation.child, "Matching should make use of root matching")
        self.assertEqual(citation.match("1.2.4"), citation.child.child, "Matching should make use of root matching")
        self.assertEqual(citation.match("1"), citation, "Matching should make use of root matching")

        self.assertEqual(citation.child.match("1.2").name, "poem", "Matching should retrieve poem at 2nd level")
        self.assertEqual(citation.child.match("1.2.4").name, "line", "Matching should retrieve line at 3rd level")
        self.assertEqual(citation.child.match("1").name, "book", "Matching retrieve book at 1st level")

        citation = citation.child
        self.assertEqual(citation.child.match("1.2").name, "poem", "Matching should retrieve poem at 2nd level")
        self.assertEqual(citation.child.match("1.2.4").name, "line", "Matching should retrieve line at 3rd level")
        self.assertEqual(citation.child.match("1").name, "book", "Matching retrieve book at 1st level")
Example #23
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(
            str(a),
            """<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(
            str(a.child),
            """<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(
            str(a.child.child),
            """<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(Reference("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\']"
        )
Example #24
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(Reference("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\']"
        )
Example #25
0
 def test_ingest_none(self):
     """ When list of node is empty or when not a list nor a node """
     a = Citation.ingest([])
     self.assertEqual(a, None)
     a = Citation.ingest({})
     self.assertEqual(a, None)
Example #26
0
    #Remove original file
    remove(file_path)
    #Move new file
    move(abs_path, file_path)

textgroups = []
works = []

xpaths_dict = {}
with open("xpaths.csv") as f:
    xp = reader(f, delimiter="\t")
    next(xp)
    for line in xp:
        path, xpaths = line[0], line[1:]
        xpaths = [x.replace("body", "body/div") for x in xpaths]
        citation = Citation(name="unknown", refsDecl="#xpath({})".format(xpaths[0]))
        last = citation
        if len(xpaths) > 1:
            for ci in xpaths[1:]:
                last.child = Citation(name="unknown", refsDecl="#xpath({})".format(ci))
                last = last.child

        xpaths_dict[path] = citation

with open("urns.csv") as f:
    csv = reader(f, delimiter="\t")
    for line in csv:
        if len(line) == 0:
            continue
        try:
            textgroup, work, _, _, _, path, tgname, workname, *_ = tuple(line)
Example #27
0
 def __init__(self, identifier: str=None, citation: Citation=None, **kwargs):
     super(TextualNode, self).__init__(identifier=identifier, **kwargs)
     self._citation = citation or Citation()
Example #28
0
 def test_ingest_none(self):
     """ When list of node is empty or when not a list nor a node """
     a = Citation.ingest([])
     self.assertEqual(a, None)
     a = Citation.ingest({})
     self.assertEqual(a, None)
Example #29
0
 def test_name(self):
     c = Citation(
         name="line"
     )
     self.assertEqual(c.name, "line")