Reputation: 11
I have a CSV file which contains 2 columns with family relations as follows:
Parent Child
Tom Jerry
Tom Mickey
Tom Simpson
Winnie Tom
I have loaded these relations into an RDF graph using this query:
INSERT { GRAPH <disney> {
?ParentIRI a <Parent> ;
<ParentRel> ?Parent .
?ChildIRI a <Child> ;
<ChildRel> ?Child .
?ParentIRI <ParentOf> ?ChildIRI .
?ChildIRI <ChildOf> ?ParentIRI .
}
}
WHERE { TABLE <file:/foobar.csv>
('csv','leader',',',true,'Parent:char,Child:char')
BIND(IRI(CONCAT("Parent",str(?Parent))) as ?ParentIRI)
BIND(IRI(CONCAT("Child",str(?Child))) as ?ChildIRI)
}
When I explore the RDF graph visually and search for node Tom, I get 2 options to choose from.
Option 1 shows graph where Tom is parent, with 2 edges between Tom and each of the 3 nodes: Jerry, Mickey and Simpson.
Where one edge in each pairing is for ChildOf
predicate and the second edge is for ParentOf
predicate.
Option 2 shows graph where Tom is child, with 2 opposite edges between Tom and Winnie for ChildOf
and ParentOf
predicates.
What I want is to combine the 2 options above into one visual graph.
That is, I want to define Tom as type person
and show all his family relations in one Visual graph, regardless of whether Tom is parent or child in the relationship.
How can I rewrite the query to achieve this?
Upvotes: 1
Views: 81
Reputation: 12207
First, please clarify in your question, which tools you are using to load and visualize the data and which kind of query that is. Your question is tagged with "sparql" but SPARQL 1.1 does not have a "TABLE" keyword.
Regardless of that, one way to solve your issue without knowing the specific tools you are using would be to create an additional property "DirectlyRelated" like this:
INSERT { GRAPH <disney> {
?ParentIRI a <Parent> ;
<ParentRel> ?Parent .
?ChildIRI a <Child> ;
<ChildRel> ?Child .
?ParentIRI <ParentOf> ?ChildIRI .
?ChildIRI <ChildOf> ?ParentIRI .
?ParentIRI <DirectlyRelated> ?ChildIRI .
?ChildIRI <DirectlyRelated> ?ParentIRI .
}
}
WHERE { TABLE <file:/foobar.csv>
('csv','leader',',',true,'Parent:char,Child:char')
BIND(IRI(CONCAT("Parent",str(?Parent))) as ?ParentIRI)
BIND(IRI(CONCAT("Child",str(?Child))) as ?ChildIRI)
}
Now you can visualize the relationships using the helper property "DirectlyRelated".
I have used your style here, but please note that usually properties are given lowerCamelCase names like parentOf or childOf. Also, some tools may reject IRIs like because you have not defined a base IRI and "ParentOf" is missing a scheme, such as http://example.org/parentOf.
Note also that depending on the specific tools used there could be a more elegant way.
Upvotes: 0