コード例 #1
0
def return_papers_by_keyword(query):
    graph = get_graph()
    matcher = NodeMatcher(graph)
    kws = matcher.match("Keyword", value__contains=query)
    retrieved_papers = set()
    papers = []
    for keyword in [Keyword(**dict(kw)).fetch() for kw in kws]:
        for paper in keyword.fetch_papers():
            if paper["ID"] in retrieved_papers:
                continue
            papers.append(paper)
            retrieved_papers.add(paper["ID"])
    return papers
コード例 #2
0
def are_related(referee_id, referenced_id):
    referee = Paper(ID=referee_id).fetch()
    referenced = Paper(ID=referenced_id).fetch()

    assert referee is not None
    assert referenced is not None

    graph = get_graph()
    matches = list(
        graph.match(
            (referee.__ogm__.node, referenced.__ogm__.node),
            r_type=REFERENCES_RELATIONSHIP,
        ))
    return len(matches) > 0
コード例 #3
0
def return_keywords(query):
    graph = get_graph()
    matcher = NodeMatcher(graph)
    kws = matcher.match("Keyword", value__contains=query)
    return [dict(kw) for kw in kws]
コード例 #4
0
def return_papers_by_title(query):
    graph = get_graph()
    matcher = NodeMatcher(graph)
    nodes = matcher.match("Paper", title__contains=query)
    return [Paper(**dict(p)) for p in nodes]