Open tian3rd opened 1 year ago
Based on discussion with @Sergio, we can start from parsing simple triples with blank nodes using _:
.
Refer to https://www.w3.org/TR/turtle/#unlabeled-bnodes for more details.
# example from https://www.w3.org/TR/turtle/#unlabeled-bnodes
_:a <http://xmlns.com/foaf/0.1/name> "Alice" .
_:a <http://xmlns.com/foaf/0.1/knows> _:b .
_:b <http://xmlns.com/foaf/0.1/name> "Bob" .
_:b <http://xmlns.com/foaf/0.1/knows> _:c .
_:c <http://xmlns.com/foaf/0.1/name> "Eve" .
_:b <http://xmlns.com/foaf/0.1/mbox> <bob@example.com> .
which is the full form of of the following abbreviated form:
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
[ foaf:name "Alice" ] foaf:knows [
foaf:name "Bob" ;
foaf:knows [
foaf:name "Eve" ] ;
foaf:mbox <bob@example.com> ] .
This is a long shot as we are aiming for a complete parser for the turtle file based on the grammar: https://www.w3.org/TR/turtle/#sec-grammar-grammar .
So the first step is to create a terminal or combinator parsers for parsing BlankNode
([137s] BlankNode ::= BLANK_NODE_LABEL | ANON)
Next, add methods in the rdflib
package to interpret the parsed result, and save the blank nodes to the Graph
.
Moreover, replace the simple parsers with more flexible parses based on GrammarDefinition
(from petitparser
)
Add tests to ensure the right results.
Current updates not yet supporting blank nodes. We do not use blank nodes our data for now although may need it sometime in future. Sergio suggests we may need some time in future. Postpone for now.
Update:
Moved this back from backlog, and started to play with the parsed blank node.
Need to refer to the implementation of python rdflib to get more ideas like the BNode
class
Status update?
URIRef
instance) and its related functions including serialization, finding related triples by criterial: e.g, Graph.subjects()
Working on this issue as I refactor the code and rewrite the examples.
Decide to go on with a new blank node class, and include to add a property of a unique URIRef id.
This is good for storing the triples in consistency with previous format: Triple(URIRef, URIRef, dynamic)
.
Based on the grammar, the example above:
[ foaf:name "Alice" ] foaf:knows [
foaf:name "Bob" ;
foaf:knows [
foaf:name "Eve" ] ;
foaf:mbox <bob@example.com> ] .
is actually not a valid triple. With a slight change to the following, it's valid though:
[]
foaf:name "Alice";
foaf:knows [
foaf:name "Bob" ;
foaf:knows [
foaf:name "Eve" ] ;
foaf:mbox <bob@example.com> ] .
Hi @tian3rd, why is the following one valid?
[]
foaf:name "Alice";
foaf:knows [
foaf:name "Bob" ;
foaf:knows [
foaf:name "Eve" ] ;
foaf:mbox <bob@example.com> ] .
As the example provided is the first one.
Hi @tian3rd, why is the following one valid?
[] foaf:name "Alice"; foaf:knows [ foaf:name "Bob" ; foaf:knows [ foaf:name "Eve" ] ; foaf:mbox <bob@example.com> ] .
As the example provided is the first one.
It's correct/incorrect according to the grammar specified here: https://www.w3.org/TR/turtle/#sec-grammar-grammar. We can have a chat if you have time, and go over some of the technical aspects of the links I sent you last week.
This is created by @Sergio, when converted from draft to issue, it removed @Sergio from the list... Probably a bug in GitHub Kanban.
We need to consider the proper RDF Data Model components: IRIs, Literals, Blank nodes, etc.
https://www.w3.org/TR/rdf11-primer/#section-blank-node https://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#section-blank-nodes