-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transformer to prune graph #638
Conversation
☂️ Python Coverage
Overall Coverage
New Files
Modified Files
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes of code requested
triples_to_delete.append((object, predicate, subject)) | ||
|
||
for delete_triple in triples_to_delete: | ||
graph.remove(triple=delete_triple) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do the same as suggested above and make customized PruneDanglingTextObjectNodes
transformer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but make sure to add attribute:
_use_only_once: bool = True
_need_changes = frozenset(
{
str(extractors.IODDExtractor.__name__),
str(ResolveValues.__name__),
}
)
from ._base import BaseTransformer | ||
|
||
|
||
class ResolveValues(BaseTransformer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this transformer is doing is reducing:
sourceNode - [propertyX] -> destinatioNode -[propertyY] -> value
sourceNode - [propertyX] -> value
so you are reducing from 2 hops to get value to single hop, so maybe more descriptive name of method would be
FlattenDualHop
|
||
for node in nodes_without_neighbours: | ||
# Remove node and its property triples in the graph | ||
graph.remove(triple=(node["subject"], None, None)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I did not know you can access subject by stating this :) ! NICE!
This implementation contains two new graph transformers means for pruning of a graph.
PruneDanglingNodes
:Removes nodes from the graph that do not have any edges to any other nodes.
ResolveValues
:Traverses the graph to find source nodes that point to other nodes with an edge to a value predicate. It then resolves this value directly to the source node, with the original predicate, so that the intermediate node can be skipped. Option to delete the intermediate node is present as well.
Used with the IODD extractor -
Graph summary before running these two transformers on the graph:
Graph summary running ResolveValues:
Graph summary after also running PruneDanglingNodes: