pyrdf2vec.graphs package¶
Submodules¶
Module contents¶
- class pyrdf2vec.graphs.KG(location=None, skip_predicates=NOTHING, literals=NOTHING, is_remote=False, *, fmt=None, mul_req=False, skip_verify=False, cache=NOTHING)¶
Bases:
object
Represents a Knowledge Graph.
- _entity_hops¶
Caches the results of asynchronous requests. Defaults to {}.
- _entities¶
Stores the entities. Defaults to set.
- _is_remote¶
True if the Knowledge Graph is in remote, False otherwise. Defaults to False.
- _vertices¶
Stores the vertices. Defaults to set.
- _inv_transition_matrix¶
Contains the parents of vertices. Defaults to defaultdict.
- _transition_matrix¶
Contains the children of vertices. Defaults to defaultdict.
- cache¶
The policy and size cache to use. Defaults to TTLCache(maxsize=1024, ttl=1200).
- connector¶
The connector to use. Defaults to SPARQLConnector.
- fmt¶
The format of the file. It should be used only if the format can not be determined from source. Defaults to None.
- literals¶
The predicate chains to get the literals. Defaults to [].
- location¶
The location of the file to load. Defaults to None.
- mul_req¶
True to allow bundling of SPARQL queries, False otherwise. This attribute accelerates the extraction of walks for remote Knowledge Graphs. Beware that this may violate the policy of some SPARQL endpoint server. Defaults to False.
- skip_predicates¶
The label predicates to skip from the KG. Defaults to set.
- skip_verify¶
To skip or not the verification of existing entities in a Knowledge Graph. Its deactivation can improve HTTP latency for KG remotes. Defaults to False.
- add_edge(v1, v2)¶
Adds a uni-directional edge.
- add_vertex(vertex)¶
Adds a vertex to the Knowledge Graph.
- add_walk(subj, pred, obj)¶
Adds a walk to the Knowledge Graph.
- fetch_hops(vertex)¶
Fetchs the hops of the vertex from a SPARQL endpoint server and add the hops for this vertex in a cache dictionary.
- get_hops(vertex, is_reverse=False)¶
Returns the hops of a vertex.
- Parameters
- Return type
- Returns
The hops of a vertex in a (predicate, object) form.
- get_literals(entities, verbose=0)¶
Gets the literals for one or more entities for all the predicates chain.
- Parameters
- Return type
- Returns
The list that contains literals for each entity.
- get_neighbors(vertex, is_reverse=False)¶
Gets the children or parents neighbors of a vertex.
- get_pliterals(entity, preds)¶
Gets the literals for an entity and a local KG based on a chain of predicates.
- is_exist(entities)¶
Checks that all provided entities exists in the Knowledge Graph.