Ejemplo n.º 1
0
 def yield_triples(self):
     self._reset_count()
     for a_line in self._line_reader.read_lines():
         tokens = self._look_for_tokens(a_line.strip())
         if len(tokens) != 3:
             self._error_triples += 1
             log_to_error(msg="This line caused error: " + a_line,
                          source=self._source_file)
         else:
             yield (tune_token(tokens[0]), tune_prop(tokens[1]),
                    tune_token(tokens[2]))
             self._triples_count += 1
 def _yield_relevant_sgraph_triples(self, target_nodes, sgraph):
     for s, p, o in sgraph.yield_p_o_triples_of_target_nodes(
             target_nodes=target_nodes,
             depth=self._depth,
             classes_at_last_level=self._classes_at_last_level,
             instantiation_property=self._instantiation_property,
             already_visited=None,
             strict_syntax_with_uri_corners=self._strict_syntax_with_corners
     ):
         yield (tune_subj(a_token=add_corners_if_it_is_an_uri(s)),
                tune_prop(a_token=add_corners(p)),
                tune_token(
                    a_token=add_corners_if_it_is_an_uri(o),
                    allow_untyped_numbers=self._allow_untyped_numbers))
Ejemplo n.º 3
0
 def yield_triples(self):
     self._reset_parsing()
     for a_line in self._line_reader.read_lines():
         for a_triple in self._process_line_2(a_line):
             self._triples_count += 1
             yield (tune_subj(a_triple[_S],
                              raise_error_if_no_corners=False),
                    tune_prop(a_triple[_P],
                              raise_error_if_no_corners=False),
                    tune_token(
                        a_triple[_O],
                        base_namespace=self._base,
                        allow_untyped_numbers=self._allow_untyped_numbers,
                        raise_error_if_no_corners=False))
Ejemplo n.º 4
0
 def yield_triples(self):
     self._reset_count()
     for a_line in self._line_reader.read_lines():
         tokens = self._look_for_tokens(a_line.strip())
         if len(tokens) != 3:
             self._error_triples += 1
             log_to_error(msg="This line was discarded: " + a_line,
                          source=self._source_file)
         else:
             yield (tune_token(a_token=tokens[0]),
                    tune_prop(a_token=tokens[1]),
                    tune_token(
                        a_token=tokens[2],
                        allow_untyped_numbers=self._allow_untyped_numbers))
             self._triples_count += 1
Ejemplo n.º 5
0
    def add_triple(self, a_triple):
        """
        It receives a tuple of 3 string elements. It adds it to the local rdflib graph
        :param a_triple:
        :return:
        """

        subj = tune_subj(add_corners_if_it_is_an_uri(a_triple[_S]),
                         raise_error_if_no_corners=False)
        prop = tune_prop(add_corners_if_it_is_an_uri(a_triple[_P]),
                         raise_error_if_no_corners=False)
        obj = tune_token(add_corners_if_it_is_an_uri(a_triple[_O]),
                         raise_error_if_no_corners=False)

        self._rdflib_graph.add((self._turn_obj_into_rdflib_element(subj),
                                self._turn_obj_into_rdflib_element(prop),
                                self._turn_obj_into_rdflib_element(obj)))
 def yield_triples(self):
     self._reset_count()
     with open(self._source_file, "r") as in_stream:
         for a_line in in_stream:
             tokens = self._look_for_tokens(a_line.strip())
             if len(tokens) != 3:
                 self._error_triples += 1
                 log_to_error(msg="This line caused error: " + a_line,
                              source=self._source_file)
             else:
                 try:
                     yield (tune_token(tokens[0]), tune_prop(tokens[1]),
                            tune_token(tokens[2],
                                       allow_untyped_numbers=True))
                     self._triples_count += 1
                 except ValueError as ve:
                     log_to_error(msg=ve.message +
                                  "This line caused error: " + a_line,
                                  source=self._source_file)