예제 #1
0
def test_transcribe_multiple_LabeledEdges():
    assert parsing.transcribe("(P31 Q42 Q5) (P106 Q3236990 Q5482740)") == [
        m.LabeledEdge(
            m.WikidataProperty("P31"),
            m.WikidataItem("Q42"),
            m.WikidataItem("Q5"),
        ),
        m.LabeledEdge(
            m.WikidataProperty("P106"),
            m.WikidataItem("Q3236990"),
            m.WikidataItem("Q5482740"),
        ),
    ]
예제 #2
0
 def visit_labelededge(self, node, children):
     """
     Instantiates a LabeledEdge for a statement of (p_id q_id q_id)
     """
     if self.debug:
         print(f"Instantiating a LabeledEdge from {children}.")
     return model.LabeledEdge(*children)
예제 #3
0
 def test_describe(self, example_statement, cached_WikidataProperty_P31,
                   cached_WikidataItem_Q42):
     assert (
         m.LabeledEdge(cached_WikidataProperty_P31, cached_WikidataItem_Q42,
                       example_statement).describe("en") ==
         "Douglas Adams → [Douglas Adams → human (instance of)] (instance of)."
     )
예제 #4
0
 def test_str(self, example_statement, cached_WikidataProperty_P31,
              cached_WikidataItem_Q42):
     assert (str(
         m.LabeledEdge(
             cached_WikidataProperty_P31,
             cached_WikidataItem_Q42,
             example_statement,
         )) == "(P31 Q42 (P31 Q42 Q5))")
예제 #5
0
def test_transcribe_mixed():
    assert parsing.transcribe("(01704452-v Q42 03833065-n)", debug=True) == [
        m.LabeledEdge(
            m.OMWSynset("01704452-v"),
            m.WikidataItem("Q42"),
            m.OMWSynset("03833065-n"),
        )
    ]
예제 #6
0
def test_transcribe_LabeledEdge():
    assert parsing.transcribe("(P31 Q42 Q5)") == [
        m.LabeledEdge(
            m.WikidataProperty("P31"),
            m.WikidataItem("Q42"),
            m.WikidataItem("Q5"),
        )
    ]
예제 #7
0
 def test_describe(
     self,
     cached_WikidataProperty_P31,
     cached_WikidataItem_Q42,
     cached_WikidataItem_Q5,
 ):
     s = m.LabeledEdge(cached_WikidataProperty_P31, cached_WikidataItem_Q42,
                       cached_WikidataItem_Q5)
     assert s.describe("en") == "Douglas Adams → human (instance of)."
예제 #8
0
 def test_str(
     self,
     cached_WikidataProperty_P31,
     cached_WikidataItem_Q42,
     cached_WikidataItem_Q5,
 ):
     s = m.LabeledEdge(cached_WikidataProperty_P31, cached_WikidataItem_Q42,
                       cached_WikidataItem_Q5)
     assert str(s) == "(P31 Q42 Q5)"
예제 #9
0
def test_transcribe_OWNSynsets():
    assert parsing.transcribe("(01835496-v 02084071-n 00110659-r)",
                              debug=True) == [
                                  m.LabeledEdge(
                                      m.OMWSynset("01835496-v"),
                                      m.OMWSynset("02084071-n"),
                                      m.OMWSynset("00110659-r"),
                                  )
                              ]
예제 #10
0
 def test_repr(self, example_statement, cached_WikidataProperty_P31,
               cached_WikidataItem_Q42):
     assert (
         repr(
             m.LabeledEdge(
                 cached_WikidataProperty_P31,
                 cached_WikidataItem_Q42,
                 example_statement,
             )) ==
         'LabeledEdge(WikidataProperty("P31"), WikidataItem("Q42"), LabeledEdge(WikidataProperty("P31"), WikidataItem("Q42"), WikidataItem("Q5")))'
     )
예제 #11
0
def test_transcribe_nested_Statements():
    assert parsing.transcribe("(Q5482740 (P31 Q42 Q5))", debug=True) == [
        m.Edge(
            m.WikidataItem("Q5482740"),
            m.LabeledEdge(
                m.WikidataProperty("P31"),
                m.WikidataItem("Q42"),
                m.WikidataItem("Q5"),
            ),
        )
    ]
예제 #12
0
 def test_repr(
     self,
     cached_WikidataProperty_P31,
     cached_WikidataItem_Q42,
     cached_WikidataItem_Q5,
 ):
     s = m.LabeledEdge(cached_WikidataProperty_P31, cached_WikidataItem_Q42,
                       cached_WikidataItem_Q5)
     assert (
         repr(s) ==
         'LabeledEdge(WikidataProperty("P31"), WikidataItem("Q42"), WikidataItem("Q5"))'
     )
예제 #13
0
def flat_statement():
    return m.LabeledEdge(
        m.WikidataProperty("P31"),
        m.WikidataItem("Q3236990"),
        m.WikidataItem("Q5482740"),
    )
예제 #14
0
def nested_statement():
    return m.Edge(
        m.WikidataItem("Q2"),
        m.LabeledEdge(m.WikidataProperty("P31"), m.WikidataItem("Q42"),
                      m.WikidataItem("Q5")),
    )
예제 #15
0
def example_statement(cached_WikidataProperty_P31, cached_WikidataItem_Q42,
                      cached_WikidataItem_Q5):
    # this is not used in tests that are of ability to construct a statement, only where that is the set up, like nesting tests.
    return m.LabeledEdge(cached_WikidataProperty_P31, cached_WikidataItem_Q42,
                         cached_WikidataItem_Q5)