コード例 #1
0
 def _read_mapping(self, filename):
     pairs = []
     with open(filename) as f:
         for line in f.readlines():
             acm_id, wiki_title = line.strip().split('\t')
             pairs.append((acm_id, to_category_uri(wiki_title)))
     return zip(*pairs)
コード例 #2
0
    def _compute_parents(self, node):
        """Returns and caches the parents (super-categories) for the given node.

        The parents are fetched from Wikipedia or from the local cache.
        Unlike self.get_parents, returns also the parents that are not in the
        'subtree' of self._root.

        """
        parents = self._parents.get(node)
        if not parents:
            #             parents = self._wiki_graph.get_supercats(node)
            self._parents[node] = set(
                to_category_uri(parent)
                for parent in self._relations.parents(node))
コード例 #3
0
    def _compute_children(self, node):
        """Returns and caches the children (subcategories) for the given node.
    
        The children are fetched from Wikipedia or from the local cache.

        """
        children = self._children.get(node)
        if children is None:
            #             children = set(self._wiki_graph.get_subcats(node) or [])
            children = set(
                to_category_uri(child)
                for child in self._relations.children(node))
            self._children[node] = children
        return children
コード例 #4
0
 def is_relevant(self, node):
     return to_category_uri(node) in self._relevant
コード例 #5
0
 def _compute_children(self, node):
     subcat_uris = self._wiki_graph.\
         get_subcats(dbpedia.to_category_uri(node))
     return sorted([dbpedia.to_title(uri) for uri in subcat_uris])
コード例 #6
0
 def is_parent(self, parent, child):
     return to_category_uri(child) in self.children(parent)
コード例 #7
0
 def _to_acm(self, node):
     return self._wiki2acm[to_category_uri(node)]
コード例 #8
0
 def contains(self, node):
     if is_acm_id(node):
         return node in self._acm2wiki
     else:
         return to_category_uri(node) in self._wiki2acm
コード例 #9
0
                if self.contains(child)
            ]
        else:
            return set()

    def is_parent(self, parent, child):
        return to_category_uri(child) in self.children(parent)

    def is_ancestor(self, parent, child):
        if self.is_parent(parent, child):
            return True
        return any([
            self.is_ancestor(parents_child, child)
            for parents_child in self.children(parent)
        ])


acm = AcmWrapper()

assert acm._acm2wiki['10002950'] == to_category_uri('Mathematics of computing')
assert acm.is_parent('World Wide Web', 'Web applications')
assert not acm.is_parent('Web applications', 'Social networks')
assert not acm.is_ancestor('World Wide Web', 'Social networks')

# import pprint
# pprint.pprint(
#     [(to_title(acm._acm2wiki[parent]), to_title(acm._acm2wiki[child]))
#      for parent in acm._children.keys()
#      for child in acm._children[parent]
#      if parent in acm._acm2wiki and child in acm._acm2wiki])
コード例 #10
0
ファイル: topic_type.py プロジェクト: kaharjan/dsw-ont-ijcai
 def is_class(self, node):
     node = to_category_uri(node)
     if self._remember_gt and node in self._ground_truth:
         return self._ground_truth[node]
     else:
         return self._predict(to_features(self._features, [node]))[0]