Пример #1
0
    def find_or_create_awesome_cate(self, cate):

        cate_node = NodeBuilder().add_label(
            "awesome category").add_entity_label().add_one_property(
                "name", cate).build()
        self.graph.merge(cate_node)
        return cate_node
Пример #2
0
 def create_alias_node_for_name(self, name, node_id):
     alias_node = NodeBuilder().add_as_alias().add_one_property("name", name).build()
     self.graph.merge(alias_node)
     alias_node_link_id_list = alias_node["link_id"]
     if alias_node_link_id_list is None or alias_node_link_id_list is []:
         alias_node["link_id"] = [node_id]
     else:
         s = set(alias_node_link_id_list)
         s.add(node_id)
         alias_node["link_id"] = list(s)
     self.graph.push(alias_node)
Пример #3
0
    def find_or_create_awesome_item_entity_by_url(self, url):
        if url.startswith("http") == False:
            return None
        node = self.find_awesome_item_by_url(url)
        if node is None:
            property_dict = {"name": url, "url": url}

            node = NodeBuilder().add_entity_label().add_label(
                "awesome item").add_property(**property_dict).build()
            self.merge_node(node)
            _logger.info("create awesome item node" + str(property_dict))
        return node
Пример #4
0
    def create_or_update_awesome_item_entity(self, url, property_dict):
        node = self.find_awesome_item_by_url(url)
        if node is None:
            node = NodeBuilder().add_entity_label().add_label(
                "awesome item").add_property(**property_dict).build()
            node = self.merge_node(node)
            _logger.info("create awesome item node" + str(property_dict))
        else:
            node = merge_property_dict_to_node(node, property_dict)
            self.push_node(node)
            _logger.info("update awesome item node" + str(property_dict))

        return node
 def create_relation_node(self, relation_name):
     '''
     create a relation by name
     :param relation_name: the relation name
     :return: the relation created or None
     '''
     if relation_name:
         node = NodeBuilder().add_label("relation").add_one_property(
             "name", relation_name).build()
         self.graph.merge(node)
         return node
     else:
         return None
    def create_so_tag_by_url(self, tag_url, name):
        '''
        create so tag by given url and name
        :param tag_url: the url of tag
        :param name: the name of the tag
        :return: the node created or exist in the server
        '''
        graph = self.get_graph_instance()
        tag_node = NodeBuilder().add_label(
            "so tag").add_entity_label().add_one_property(
                "name", name).add_one_property("Stack Overflow tag url",
                                               tag_url).build()

        graph.merge(tag_node)
        return tag_node
 def create_wikipedia_item_entity_by_url(self, url):
     if url.startswith("https://en.wikipedia.org/") == False:
         return None
     accessor = DefaultGraphAccessor(self)
     node = accessor.get_node_by_wikipedia_link(url)
     if node is None:
         property_dict = {
             "name": wiki_title(url.split("/")[-1]),
             "url": url,
             "site:enwiki": url
         }
         if "(" in property_dict["name"]:
             alias = [(property_dict["name"].split(" ("))[0]]
             property_dict["alias"] = alias
         node = NodeBuilder().add_entity_label().add_label(
             "wikipedia").add_property(**property_dict).build()
         self.graph.merge(node)
         _logger.info("create wikipedia node" + str(property_dict))
     return node
Пример #8
0
    def create_random_walk_similarity_by_transaction(
            self, random_walk_similarity_list):
        '''
        :param random_walk_similarity_list: is a list, each is a json,stand for the random walk similarity.

        example: [{"start_link_id": 4, "end_link_id": 6, "count": 0.1},
                                   {"start_link_id": 4, "end_link_id": 7, "count": 0.1}]
        :return: the response
        '''

        link_id_list = []
        for random_walk_similarity in random_walk_similarity_list:
            link_id_list.append(random_walk_similarity["start_link_id"])
            link_id_list.append(random_walk_similarity["end_link_id"])
        link_id_list = list(set(link_id_list))

        entity_node_map = {}
        graph = self.get_graph_instance()
        transaction = graph.begin()
        for link_id in link_id_list:
            entity_node = NodeBuilder().add_label("Entity").add_one_property(
                "link_id", link_id).build()
            transaction.merge(entity_node)
            entity_node_map[str(link_id)] = entity_node

        new_random_walk_similarity_list = []
        for random_walk_similarity in random_walk_similarity_list:
            start_link_id = str(random_walk_similarity["start_link_id"])
            end_link_id = str(random_walk_similarity["end_link_id"])

            start_node = entity_node_map[start_link_id]
            end_node = entity_node_map[end_link_id]
            relation = Relationship(start_node, "connect", end_node)
            transaction.merge(relation)
            random_walk_similarity["relation"] = relation
            new_random_walk_similarity_list.append(random_walk_similarity)
        transaction.commit()
        for random_walk_similarity in new_random_walk_similarity_list:
            relation = random_walk_similarity["relation"]
            relation["count"] = random_walk_similarity["count"]
            graph.push(relation)
Пример #9
0
 def find_or_create_alias_node(self, alias):
     end_node = NodeBuilder().add_as_alias().add_one_property(
         property_name='name', property_value=alias).build()
     self.graph.merge(end_node)
     return end_node