예제 #1
0
    def test_not_equal(self):
        fetched_Q = fetch_query("llevaron", "Spanish")
        Llevaron = wx.graph(fetched_Q)

        fetched_Q = fetch_query("llevar", "Spanish")
        Llevar = wx.graph(fetched_Q)

        assert not nx.is_isomorphic(Llevar, Llevaron)
예제 #2
0
def test_to_dict_of_lists_equivalence():
    return True # this shouldn't change very much
    _Q = test_.fetch_query("prototype", "English")
    G = wikt_api.graph(_Q)
    wikt_api.draw_graph(G, pause=True)
    dl = nx.to_dict_of_lists(G)
    print(dl)
    G2 = nx.from_dict_of_lists(dl, create_using=nx.DiGraph)
    wikt_api.draw_graph(G2, pause=True)
    dl2 = nx.to_dict_of_lists(G2)
    assert dl == dl2
예제 #3
0
    def test_missing_definition_graph(self):
        # etyobjects.reset_global_o_id()

        fetched_Q = fetch_query("statt", "German")
        # TODO: investigate the effect of flattening on this line
        G = wx.graph(fetched_Q)
        G2 = nx.DiGraph()
        G2.add_node(fetched_Q.origin)
        assert nx.is_isomorphic(G, G2)
        assert len(G.nodes) == 1
        assert [n for n in G.nodes] == [n for n in G2.nodes]
예제 #4
0
    def test_lemma_llevaron(self):
        # etyobjects.reset_global_o_id()

        fetched_Q = fetch_query("llevaron", "Spanish")
        G = wx.graph(fetched_Q)
        global G_llevaron
        G2 = G_llevaron # this is the repr() version of each node
        assert nx.is_isomorphic(G, G2)

        assert [repr(s) for s in G.nodes] == [s for s in reversed(list(G2.nodes))] # nx reversed the nodes for some reason
        assert [(repr(l), repr(r)) for l, r in G.edges] == [e for e in reversed(list(G2.edges))]
예제 #5
0
    def test_graph(self, monkeypatch):
        # etyobjects.reset_global_o_id()
        # monkeypatch.setattr('builtins.input', lambda _: "1") #Multiple Definitions
        fetched_Q = fetch_query("llevar", "Spanish")
        G = wx.graph(fetched_Q)
        global G_llevar
        G2 = G_llevar
        assert nx.is_isomorphic(G, G2)

        assert [repr(s) for s in G.nodes] == [s for s in reversed(list(G2.nodes))] # nx reversed the nodes for some reason
        assert [(repr(l), repr(r)) for l, r in G.edges] == [e for e in reversed(list(G2.edges))]
예제 #6
0
    def test_graph(self, monkeypatch):
        monkeypatch.setattr('builtins.input',
                            lambda _: "1")  # Multiple Definitions
        _Q = fetch_query("adelante", "Spanish")
        # TODO: investigate the effect of flattening on this line
        G = wx.graph(_Q)
        G2 = nx.DiGraph()
        nx.add_path(
            G2, ["adelante#Spanish$0", "$0{m|Spanish|delante ['in front']}"])
        assert nx.is_isomorphic(G, G2)

        assert [repr(s) for s in G.nodes] == [s for s in G2.nodes]
예제 #7
0
def test_graph_eq():
    # etyobjects.reset_global_o_id()

    _Q = test_.fetch_query("prototype", "English")
    G = wikt_api.graph(_Q)
    # wikt_api.draw_graph(G, pause=True)
    dl = nx.to_dict_of_lists(G)
    print(dl)
    assert repr(dl) == "{prototype#English$0: [], $0{der|French|prototype}: [prototype#English$0], $0{der|Late Latin|prototypon}: " \
                       "[$0{der|French|prototype}], $0{der|Ancient Greek|πρωτότυπος ['', 'original; prototype']}: " \
                       "[$0{der|Late Latin|prototypon}], $0{m|Ancient Greek|πρωτο- [\"''prefix meaning ‘first’''\"]}: " \
                       "[$0{der|Ancient Greek|πρωτότυπος ['', 'original; prototype']}], $0{m|Ancient Greek|πρῶτος ['first; earliest']}: " \
                       "[$0{m|Ancient Greek|πρωτο- [\"''prefix meaning ‘first’''\"]}], $0{m|Ancient Greek|τῠ́πος ['blow, pressing; sort, type']}: " \
                       "[$0{m|Ancient Greek|πρωτο- [\"''prefix meaning ‘first’''\"]}], $0{m|Ancient Greek|τύπτω ['to beat, strike']}: " \
                        "[$0{m|Ancient Greek|τῠ́πος ['blow, pressing; sort, type']}], $0{der|Proto-Indo-European|*(s)tewp- ['', 'to push; to stick']}: " \
                       "[$0{m|Ancient Greek|τύπτω ['to beat, strike']}]}"
예제 #8
0
파일: main.py 프로젝트: phlaxyr/pyetymology
def mainloop(test_queries: List[Tuple[str, str]] = None,
             draw_graphs=True,
             cog_search_langs=None,
             run_queries: List[str] = None) -> List[nx.DiGraph]:
    original_query = ""  # lleno#Spanish"#llenar#Spanish"#"conflate#English"#"llegar#Spanish"#"Reconstruction:Proto-Italic/feiljos#"
    # etyobjects.reset_global_o_id()  # TODO: avoid global state in Originator
    total_queries = 0
    _EXIT = object()
    retn = []

    def test_safe_query(original_query, working_G=None):
        nonlocal total_queries
        nonlocal test_queries
        nonlocal run_queries
        nonlocal _EXIT
        if test_queries:
            if total_queries >= len(test_queries):
                return _EXIT
            _q1 = test_.fetch_query(*test_queries[total_queries],
                                    query_id=total_queries)
        elif run_queries:
            if total_queries >= len(run_queries):
                return _EXIT
            potential = run_queries[total_queries]
            if potential:
                print(f"querying:{potential}")
                _q1 = ety.query(me=potential,
                                query_id=total_queries,
                                working_G=working_G)
            else:
                print("Prematurely exiting!")
                return _EXIT
        else:
            _q1 = ety.query(me=original_query,
                            query_id=total_queries,
                            working_G=working_G)
        total_queries += 1
        return _q1

    #_q1 = test_safe_query(original_query)
    #if _q1 is _EXIT:  # exit condition
    #    return None
    #GG = ety.graph(_q1)
    #ety.draw_graph(GG)
    #_ = [print(x) for x in GG.nodes]
    GG = None
    while True:
        assert True
        _Q = test_safe_query(
            "", working_G=GG)  # ask for another query from the user
        if _Q is _EXIT:  # exit condition
            retn.append(GG)
            return retn

        query_origin = _Q.origin
        if GG:
            GG_origin = ety.find_node_by_origin(GG, query_origin)
        else:
            GG_origin = None
        # We want to connect these two graphs,
        # so we take our query's origin and try to find
        # a node from our big, working tree GG.

        G = ety.graph(_Q,
                      replacement_origin=GG_origin,
                      cog_search_langs=cog_search_langs)
        if test_queries:
            retn.append(G)
        if draw_graphs:
            ety.draw_graph(G, pause=True)
        _ = [print(x) for x in G.nodes]

        if GG_origin:

            # good, we found a connection
            # fuse the graphs, which should now be connected because we fused and forced our tree G to use a preexisting origin.
            GG = nx.compose(GG, G)
            if draw_graphs:
                ety.draw_graph(GG)
        else:
            if total_queries != 1:  # warn unconnected queries, unless it's the initial query in which it's OK
                warnings.warn("Unconnected query " + str(_Q.origin))
            GG = G
            continue
        """