Esempio n. 1
0
 def get_by_id(tim_id):
     query = """
     MATCH (tim:Time{entityID: $tim_id}) 
     RETURN tim.entityID as entityID, tim.name as name, tim.des as description
     """
     result = dao.run_read_query(query, tim_id=tim_id).data()
     return convert_date_results_to_string(result)
Esempio n. 2
0
 def get_detailed_facts_in_news(news_id: str):
     query = """
     MATCH(news:News{entityID: $id_news})-[:HAS_FACT]->(facts:Fact)
     USING INDEX news:News(entityID)
     WITH facts
     MATCH (facts)-[r]->(entity)
     RETURN facts.entityID as factID, collect(type(r)) as predicate, collect(entity.entityID) as entityID
     """
     result = dao.run_read_query(query, {"id_news": news_id}).data()
     facts = []
     for res in result:
         detailed_fact = {"timeID": None, "locationID": None}
         detailed_fact["factID"] = res["factID"]
         predicate = res["predicate"]
         for pre in predicate:
             if pre == "OCCURRED_ON":
                 detailed_fact["timeID"] = res["entityID"][predicate.index(
                     pre)]
             elif pre == "OCCURRED_IN":
                 detailed_fact["locationID"] = res["entityID"][
                     predicate.index(pre)]
             elif pre.find("HAS_SUBJECT") > -1:
                 detailed_fact["subjectID"] = res["entityID"][
                     predicate.index(pre)]
                 relation = pre[len("HAS_SUBJECT") + 1:].replace("_", " ")
                 detailed_fact["relation"] = relation
             else:
                 detailed_fact["objectID"] = res["entityID"][
                     predicate.index(pre)]
         facts.append(detailed_fact)
     return facts
Esempio n. 3
0
 def get_by_id(news_id: str):
     query = '''
     MATCH (news:News {entityID : $id})
     USING INDEX news:News(entityID) 
     RETURN news.entityID as entityID, news.link as link, news.topics as topics
     '''
     return dao.run_read_query(query, id=news_id).data()
Esempio n. 4
0
 def get_all_relations_in_news(news_id: str) -> Dict:
     query = """
     MATCH (news:News{entityID: $id})-[:HAS_FACT]->(facts:Fact)-[rel]->(entity)
     USING INDEX news:News(entityID)
     RETURN facts, rel, entity
     """
     result = dao.run_read_query(query, id=news_id).graph()
     return serialize_subgraph_to_dict(result)
Esempio n. 5
0
 def get_all(start=0, limit=100) -> List:
     query = """
     MATCH (per:Person)
     RETURN per.entityID as entityID, per.name as name, per.des as description
     ORDER BY per.entityID
     SKIP $start
     LIMIT $limit
     """
     return dao.run_read_query(query, start=start, limit=limit).data()
Esempio n. 6
0
 def get_all(start=0, limit=100) -> List:
     query = """
     MATCH (org:Organization)
     RETURN org.entityID as entityID, org.name as name, org.des as description
     ORDER BY org.entityID
     SKIP $start
     LIMIT $limit
     """
     return dao.run_read_query(query, start=start, limit=limit).data()
Esempio n. 7
0
 def get_all(start=0, limit=100) -> List:
     query = """
     MATCH (agr:Agreement)
     RETURN agr.entityID as entityID, agr.name as name, agr.des as description
     ORDER BY agr.entityID
     SKIP $start
     LIMIT $limit
     """
     return dao.run_read_query(query, start=start, limit=limit).data()
Esempio n. 8
0
 def get_all(start=0, limit=100) -> List:
     query = """
     MATCH (cty:Country)
     RETURN cty.entityID as entityID, cty.name as name, cty.des as description
     ORDER BY cty.entityID
     SKIP $start
     LIMIT $limit
     """
     return dao.run_read_query(query, start=start, limit=limit).data()
Esempio n. 9
0
 def get_all(start=0, limit=100) -> List:
     query = """
     MATCH (event:Event)
     RETURN event.entityID as entityID, event.name as name, event.des as description
     ORDER BY event.entityID
     SKIP $start
     LIMIT $limit
     """
     return dao.run_read_query(query, start=start, limit=limit).data()
Esempio n. 10
0
 def get_all(start=0, limit=100) -> List:
     query = """
     MATCH (loc:Location)
     RETURN loc.entityID as entityID, loc.name as name, loc.des as description
     ORDER BY loc.entityID
     SKIP $start
     LIMIT $limit
     """
     return dao.run_read_query(query, start=start, limit=limit).data()
Esempio n. 11
0
 def search_entity(input_type_entity, input_text) -> List:
     query = """
     MATCH(entity)
     WHERE any( label IN labels(entity) WHERE label IN $type_entity) AND entity.des CONTAINS $property
     RETURN entity.entityID as entityID, entity.name as name, entity.des as description
     """
     return dao.run_read_query(query, {
         "type_entity": input_type_entity,
         "property": input_text
     }).data()
Esempio n. 12
0
 def is_in_news(tim_id) -> bool:
     query = """
     MATCH (fact:Fact)-[]->(:Time{entityID: $id_entity})
     RETURN count(fact) as numAppearance
     """
     result = dao.run_read_query(query, id_entity=tim_id).data()
     if result[0]["numAppearance"] == 0:
         return False
     else:
         return True
Esempio n. 13
0
 def get_all(start=0, limit=100) -> List:
     query = """
     MATCH (tim:Time)
     RETURN tim.entityID as entityID, tim.name as name, tim.des as description
     ORDER BY tim.entityID
     SKIP $start
     LIMIT $limit
     """
     result = dao.run_read_query(query, start=start, limit=limit).data()
     return convert_date_results_to_string(result)
Esempio n. 14
0
 def get_number_appearance_in_news(news_id: str, entity_id: str) -> Dict:
     query = """
     MATCH (news:News{entityID: $id_news})-[:HAS_FACT]->(facts:Fact)-[]->({entityID:$id_entity})
     USING INDEX news:News(entityID)
     RETURN count(facts) as numberAppearance
     """
     result = dao.run_read_query(query, {
         "id_news": news_id,
         "id_entity": entity_id
     }).data()
     return {"numberAppearance": result[0]["numberAppearance"]}
Esempio n. 15
0
 def get_all_relations_in_set_news(set_news_id: List[str]) -> Dict:
     id_set_news = list(set(set_news_id))
     if len(id_set_news) > LIMIT_NEWS:
         id_set_news = id_set_news[:LIMIT_NEWS]
     query = """
     UNWIND $set_news_id as news_id
     MATCH (news:News{entityID:news_id})-[:HAS_FACT]->(facts:Fact)-[rel]->(entity)
     USING INDEX news:News(entityID)
     RETURN facts, rel, entity
     """
     result = dao.run_read_query(query, set_news_id=id_set_news).graph()
     return serialize_subgraph_to_dict(result)
Esempio n. 16
0
 def get_all(start=0, limit=100) -> List:
     query = """
     MATCH (news:News)
     RETURN news.entityID as entityID, news.link as link, news.topics as topics
     ORDER BY news.entityID
     SKIP $start
     LIMIT $limit
     """
     return dao.run_read_query(query, {
         "start": start,
         "limit": limit
     }).data()
Esempio n. 17
0
 def get_entity_type_relations_in_news(news_id: str,
                                       entity_type: List[str]) -> Dict:
     query = """
     MATCH (news:News{entityID: $id_news})-[:HAS_FACT]->(facts:Fact)-[rel]->(entity)
     USING INDEX news:News(entityID)
     WHERE any( label IN labels(entity) WHERE label IN $type_entity)
     RETURN facts, rel, entity
     """
     result = dao.run_read_query(query, {
         "id_news": news_id,
         "type_entity": list(set(entity_type))
     }).graph()
     return serialize_subgraph_to_dict(result)
Esempio n. 18
0
 def search_news(start=0, limit=100, *args, **kwargs) -> List:
     query = """
     MATCH(news:News)
     WHERE news.link CONTAINS $property
     RETURN news.entityID as entityID, news.link as link, news.topics as topics
     ORDER BY news.entityID
     SKIP $start
     LIMIT $limit
     """
     return dao.run_read_query(query, {
         "property": args[0],
         "start": start,
         "limit": limit
     }).data()
Esempio n. 19
0
 def get_entity_individual_relations_in_news(news_id: str,
                                             entity_id: str) -> Dict:
     query = """
     MATCH (news:News{entityID: $id_news})-[:HAS_FACT]->(fact:Fact)-[]->({entityID:$id_entity})
     USING INDEX news:News(entityID)
     WITH fact
     MATCH (fact)-[rel]->(entity)
     RETURN fact, rel, entity
     """
     result = dao.run_read_query(query, {
         "id_news": news_id,
         "id_entity": entity_id
     }).graph()
     return serialize_subgraph_to_dict(result)
Esempio n. 20
0
 def get_number_appearance_in_set_news(set_news_id: List[str],
                                       entity_id: str) -> Dict:
     id_set_news = list(set(set_news_id))
     if len(id_set_news) > LIMIT_NEWS:
         id_set_news = id_set_news[:LIMIT_NEWS]
     query = """
     UNWIND $set_id_news as news_id
     MATCH (news:News{entityID: news_id})-[:HAS_FACT]->(facts:Fact)-[]->({entityID:$id_entity})
     USING INDEX news:News(entityID)
     RETURN count(facts) as numberAppearance
     """
     result = dao.run_read_query(query, {
         "set_id_news": id_set_news,
         "id_entity": entity_id
     }).data()
     return {"numberAppearance": result[0]["numberAppearance"]}
Esempio n. 21
0
    def search(start=0, limit=100, *args, **kwargs):

        query = """
            MATCH(entity:Time)
            WHERE entity.des CONTAINS $property OR entity.name CONTAINS $property
            RETURN entity.entityID as entityID, entity.name as name, entity.des as description
            ORDER BY entity.entityID
            SKIP $start
            LIMIT $limit
            """
        result = dao.run_read_query(query, {
            "property": args[0],
            "start": start,
            "limit": limit
        }).data()
        return convert_date_results_to_string(result)
Esempio n. 22
0
 def get_entity_type_relations_in_set_news(set_news_id: List[str],
                                           entity_type: List[str]) -> Dict:
     id_set_news = list(set(set_news_id))
     if len(id_set_news) > LIMIT_NEWS:
         id_set_news = id_set_news[:LIMIT_NEWS]
     query = """
     UNWIND $set_id_news as news_id
     MATCH (news:News{entityID: news_id})-[:HAS_FACT]->(facts:Fact)-[rel]->(entity)
     USING INDEX news:News(entityID)
     WHERE any( label IN labels(entity) WHERE label IN $type_entity)
     RETURN facts, rel, entity
     """
     result = dao.run_read_query(query, {
         "set_id_news": id_set_news,
         "type_entity": list(set(entity_type))
     }).graph()
     return serialize_subgraph_to_dict(result)
Esempio n. 23
0
 def get_entity_individual_relations_in_set_news(set_news_id: List[str],
                                                 entity_id: str) -> Dict:
     id_set_news = list(set(set_news_id))
     if len(id_set_news) > LIMIT_NEWS:
         id_set_news = id_set_news[:LIMIT_NEWS]
     query = """
     UNWIND $set_id_news as news_id
     MATCH (news:News{entityID: news_id})-[:HAS_FACT]->(facts:Fact)-[]->({entityID:$id_entity})
     USING INDEX news:News(entityID)
     WITH facts
     MATCH (facts)-[rel]->(entity)
     RETURN facts, rel, entity
     """
     result = dao.run_read_query(query, {
         "set_id_news": id_set_news,
         "id_entity": entity_id
     }).graph()
     return serialize_subgraph_to_dict(result)
Esempio n. 24
0
 def get_fact_by_id(fact_id: str):
     query = """
     MATCH (fact:Fact{entityID: $id_fact})
     RETURN fact
     """
     return dao.run_read_query(query, id_fact=fact_id).data()
Esempio n. 25
0
 def checkUserAccount(username, password):
     query = """
        MATCH (usr:User { username: $usr, password: $paswd })
        RETURN usr.username as username, usr.password as password, usr.isAdmin as isAdmin
        """
     return dao.run_read_query(query, usr=username, paswd=password).data()
Esempio n. 26
0
 def getAdmin(username):
     query = """
     MATCH (usr:Admin { username: $usr})
     RETURN usr.username as username, usr.password as password, usr.isAdmin as isAdmin
     """
     return dao.run_read_query(query, usr=username).data()
Esempio n. 27
0
 def search(start=0, limit=100, *args, **kwargs):
     text_search = args[0]
     query = "CALL db.index.fulltext.queryNodes(" + "'countriesFullTextSearch', '" + text_search + \
             "') YIELD node, score  RETURN node.entityID as entityID, node.name as name," \
             "node.des as description, score ORDER BY score DESC"
     return dao.run_read_query(query).data()[start:start + limit]
Esempio n. 28
0
 def get_by_id(cty_id):
     query = """
     MATCH (cty:Country{entityID: $cty_id})
     RETURN cty.entityID as entityID, cty.name as name, cty.des as description
     """
     return dao.run_read_query(query, cty_id=cty_id).data()
Esempio n. 29
0
 def get_by_id(org_id):
     query = """
     MATCH (org:Organization{entityID: $org_id}) 
     RETURN org.entityID as entityID, org.name as name, org.des as description
     """
     return dao.run_read_query(query, org_id=org_id).data()
Esempio n. 30
0
 def get_by_id(agr_id):
     query = """
     MATCH (agr:Agreement{entityID: $agr_id}) 
     RETURN agr.entityID as entityID, agr.name as name, agr.des as description
     """
     return dao.run_read_query(query, agr_id=agr_id).data()