forayer.input_output.from_to_rdf¶
Read and write semantic web sources.
Functions
|
Add a value to a set or create a new set with prev and new. |
|
Casts a literal to the respective python type. |
|
Create forayer knowledge graph object from rdflib graph. |
|
Create knowledge graph object from rdf source. |
|
Write the forayer knowledge graph to a rdf serialization format. |
- forayer.input_output.from_to_rdf.add_multi_value(prev, new) Set[source]¶
Add a value to a set or create a new set with prev and new.
- prev
Existing value.
- new
New value, that should be added.
- Set
Set containing the previous and new elements.
- forayer.input_output.from_to_rdf.cast_to_python_type(lit: rdflib.term.Literal)[source]¶
Casts a literal to the respective python type.
- litrdflib.term.Literal
The literal that is to be cast.
- Any
The literal as the respective python object
- forayer.input_output.from_to_rdf.from_rdflib(graph: rdflib.graph.Graph, literal_cleaning_func: Optional[Callable] = None, kg_name: Optional[str] = None, multi_value: Optional[Callable] = None) forayer.knowledge_graph.kg.KG[source]¶
Create forayer knowledge graph object from rdflib graph.
- graphrdflib.Graph
Rdflib graph to transform.
- literal_cleaning_func: Callable
Function to preprocess literals, if None will simply cast to python types.
- formatstr
Triple format (“xml”, “n3” (use for turtle), “nt” or “trix”).
- kg_namestr
How to name the knowledge graph object.
- multi_valueCallable
How to handle multiple attribute values for an entity, attribute name combination. Default creates a set and adds to it
- KG
the transformed kg object
- forayer.input_output.from_to_rdf.load_from_rdf(in_path: str, literal_cleaning_func: Optional[Callable] = None, format: Optional[str] = None, kg_name: Optional[str] = None, multi_value: Optional[Callable] = None) forayer.knowledge_graph.kg.KG[source]¶
Create knowledge graph object from rdf source.
- in_pathstr
Path of triple file.
- literal_cleaning_func: Callable
Function to preprocess literals, if None will simply cast to python types.
- formatstr
Triple format (“xml”, “n3” (use for turtle), “nt” or “trix”).
- kg_namestr
How to name the knowledge graph object.
- multi_valueCallable
How to handle multiple attribute values for an entity, attribute name combination. Default creates a set and adds to it
- KG
the loaded kg object
- forayer.input_output.from_to_rdf.write_to_rdf(kg: forayer.knowledge_graph.kg.KG, out_path: str, format: str, prefix: str = '', attr_mapping: Optional[dict] = None)[source]¶
Write the forayer knowledge graph to a rdf serialization format.
- kgKG
The knowledge graph that will be serialized.
- out_pathstr
The path where it should be serialized to.
- formatstr
The desired rdf format.
- prefixstr
Prefix for the entities in the graph.
- attr_mappingdict
Mapping of attribute names.
