Exemplo n.º 1
0
 def fit(self, X=None, y=None, **kwargs):
     """Creates the mapping from concepts
     to the thesauri that are broader than the concept."""
     broaders = list(
         t.extract_relation_by_uri(self.graph, self.thesaurus_relation,
                                   self.inverse_relation))
     concept_po = _collect_po_from_tuples(
         t.filter_subject_tuples_from_set(broaders, self.concepts))
     thesauri_po = _collect_po_from_tuples(
         t.filter_subject_tuples_from_set(broaders, self.thesauri),
         self.thesauri)
     for thesaurus in self.thesauri:
         thesauri_po[thesaurus].add(thesaurus)
     thesauri_closure = set_closure(thesauri_po)
     thesaurus_indices = dict(
         zip(thesauri_closure, range(len(thesauri_closure))))
     concept_thesauri_mapping = {
         concept: set.union(*(thesauri_closure.get(broader, set())
                              for broader in broaders))
         for concept, broaders in concept_po.items()
     }
     self.feature_dim_ = max(len(thesaurus_indices), 1)
     self.mapping_ = {
         str(concept): csr_matrix(
             ([1 for _ in thesaurii],
              ([0 for _ in thesaurii],
               [thesaurus_indices[thesaurus] for thesaurus in thesaurii])),
             shape=(1, len(thesaurus_indices)))
         for concept, thesaurii in concept_thesauri_mapping.items()
     }
     return self
Exemplo n.º 2
0
def test_closure_of_tree(tree_relation):
    closures = set_closure(tree_relation)
    check_tree_closure(closures)
Exemplo n.º 3
0
def test_no_exception_on_non_cycle_backedge(tree_relation):
    tree_relation, additionals = _add_edge_to_tree_relation(
        tree_relation, _internal_nodes - 2, 1)
    closures = set_closure(tree_relation)
    check_tree_closure(closures, additionals)
Exemplo n.º 4
0
def test_exception_on_cycle(tree_relation):
    tree_relation[_internal_nodes - 2].add(_branching_k)
    with raises(RelationLoopException):
        set_closure(tree_relation)
Exemplo n.º 5
0
def test_closure_double_diamond_reflexive(double_diamond_reflexive):
    p_order, additionals = double_diamond_reflexive
    closures = set_closure(p_order)
    check_tree_closure(closures, additionals)
    for n in p_order:
        assert n in closures[n]
Exemplo n.º 6
0
def test_closure_double_diamond(double_diamond):
    p_order, additionals = double_diamond
    closures = set_closure(p_order)
    check_tree_closure(closures, additionals)