anusii / rdflib Goto Github PK
View Code? Open in Web Editor NEWA pure Dart package for working with RDF (resource description framework).
Home Page: https://pub.dev/packages/rdflib
License: GNU General Public License v3.0
A pure Dart package for working with RDF (resource description framework).
Home Page: https://pub.dev/packages/rdflib
License: GNU General Public License v3.0
13 Oct 10:34:05 gjw@yoga ~gurriny/clinic$ flutter pub upgrade --dry-run
Resolving dependencies... (4.3s)
Because clinic depends on rdflib ^0.2.4 which depends on http ^0.13.5, http ^0.13.5 is required.
So, because clinic depends on http ^1.1.0, version solving failed.
You can try the following suggestion to make the pubspec resolve:
* Consider downgrading your constraint on http: flutter pub add http:^0.13.6
The link to SOLID Health Ontology Example is not working and shows the repository is deleted, could you add that back?
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
rdflib (version 0.2.8) throws an exception when parsing the get response of a directory with two resources:
ind-keys.ttl
enc-keys.ttl
Here's the exception
Unhandled exception:
type 'List<dynamic>' is not a subtype of type 'String'
#0 Graph._saveToGroups (package:rdflib/src/graph.dart:614:7)
#1 Graph.parseTurtle (package:rdflib/src/graph.dart:584:7)
And here's the response turtle string I want to parse
@prefix dc: <http://purl.org/dc/terms/>.
@prefix ldp: <http://www.w3.org/ns/ldp#>.
@prefix posix: <http://www.w3.org/ns/posix/stat#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
<> <urn:npm:solid:community-server:meta:contentTypeParameter> _:b22466_b12514_b12510_n3-564;
a ldp:Container, ldp:BasicContainer, ldp:Resource;
dc:modified "2024-07-10T00:36:05.000Z"^^xsd:dateTime.
_:b22466_b12514_b12510_n3-564 <http://www.w3.org/2000/01/rdf-schema#label> "charset";
<urn:npm:solid:community-server:meta:value> "utf-8".
<ind-keys.ttl> a ldp:Resource, <http://www.w3.org/ns/iana/media-types/text/turtle#Resource>;
dc:modified "2024-07-10T04:54:04.000Z"^^xsd:dateTime.
<enc-keys.ttl> a ldp:Resource, <http://www.w3.org/ns/iana/media-types/text/turtle#Resource>;
dc:modified "2024-06-27T12:01:32.000Z"^^xsd:dateTime.
<> posix:mtime 1720571765;
ldp:contains <ind-keys.ttl>, <enc-keys.ttl>.
<ind-keys.ttl> posix:mtime 1720587244;
posix:size 941.
<enc-keys.ttl> posix:mtime 1719489692;
posix:size 2703.
Had a Zoom meeting with @ZheYuan and @sergio last Friday discussing about how to develop the rdfgraph
and integrate it in our formapp
.
For me, the focus this week would be adding three more essential methods in the graph
:
ttl
turtle file and store triples in the graph (related to #593 )The above three functions in the graph will be enough for @ZheYuan to test the sample turtle data file created by Sergio.
First, create a class ExpressionDefinition
that extends GrammarDefinition
, and its purpose is to include all 50 turtle rules inside as parsers.
Second, for most common turtle files such as .acl
and our .ttl
file in PODS repo, create a EvaluatorDefinition
class whose main purpose is to attach custom production actions to interpret the outcomes of the parsers. With rdflib
classes such as URIRef
, Graph
, we can save the results in the graph.
@Prefix : <#>.
@Prefix dct: http://purl.org/dc/terms/.
@Prefix ldp: http://www.w3.org/ns/ldp#.
@Prefix stat: http://www.w3.org/ns/posix/stat#.
@Prefix xsd: http://www.w3.org/2001/XMLSchema#.
@Prefix klee: <>.
@Prefix ge: .
@Prefix sur: .
@Prefix tur: http://www.w3.org/ns/iana/media-types/text/turtle#.
klee:
a ldp:BasicContainer, ldp:Container;
dct:modified "2023-02-28T09:34:09Z"^^xsd:dateTime;
ldp:contains ge:, <klee.ttl>, sur:;
stat:mtime 1677576849.377;
stat:size 4096 .
ge:
a ldp:BasicContainer, ldp:Container, ldp:Resource;
dct:modified "2023-02-28T09:33:10Z"^^xsd:dateTime;
stat:mtime 1677576790.772;
stat:size 4096 .
<klee.ttl>
a tur:Resource, ldp:Resource;
dct:modified "2023-02-23T00:40:35Z"^^xsd:dateTime;
stat:mtime 1677112835.601;
stat:size 483 .
sur:
a ldp:BasicContainer, ldp:Container, ldp:Resource;
dct:modified "2023-02-28T09:34:11Z"^^xsd:dateTime;
stat:mtime 1677576851.761;
stat:size 4096 .
this file is collected from solid community and every time I tried to parse it, an exception occur
E.g.,
// ...
Graph g = Graph();
g.parse('http://www.w3.org/People/Berners-Lee/card');
// ...
The next step is to integrate the parsers into the more flexible GrammarDefinition
classes, and interpret them into triples, prefix namespaces, and finally save all the information in the Graph. Will create another issue for this next step.
It would be easy for user to find where the error is when parseTurtle raises exception.
petitparser
package provides readily made terminal parsers such as letter()
, digit()
, string()
that can be used to parse simple snippets. To take a step further, we can also combine parsers together to get more complicated functions such as chaining parsers, specifying the repeated time a pattern should occur in a string, etc.
For starters, refer to #625 for the tasks of parsing IRIREF
and PN_CHARS_U
, and use combinator parsers to parse different strings.
Some turtle formats are not supported by the Rdflib parser. Following are some examples.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ex: <http://example.org/stuff/1.0/> .
<http://www.w3.org/TR/rdf-syntax-grammar>
dc:title "RDF/XML Syntax Specification (Revised)" ;
ex:editor [
ex:fullname "Dave Beckett";
ex:homePage <http://purl.org/net/dajobe/>
] .
@prefix : <http://example.org/stuff/1.0/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
:a :b
[ rdf:first "apple";
rdf:rest [ rdf:first "banana";
rdf:rest rdf:nil ]
] .
The issue is the extension of issue #34
Clean the package and add the PUB POINTS.
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh_data: <http://yarrabah.net/data/solid-health#> .
@prefix sh_onto: <http://sii.cecs.anu.edu.au/onto/solid-health#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
sh_data:Info-17809g89a a sh_onto:InfoTab,
owl:NamedIndividual ;
rdfs:label "label_name"^^xsd:string ;
sh_onto:commentP """1. First comment.
2. Second comment.
3. Third comment."""^^xsd:string .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix show: <http://example.org/vocab/show/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
show:218 rdfs:label "That Seventies Show"^^xsd:string .
show:218 rdfs:label "That Seventies Show"^^<http://www.w3.org/2001/XMLSchema#string> .
show:218 rdfs:label "That Seventies Show" .
show:218 show:localName "That Seventies Show"@en .
show:218 show:localName 'Cette Série des Années Soixante-dix'@fr .
show:218 show:localName "Cette Série des Années Septante"@fr-be .
show:218 show:blurb '''This is a multi-line
literal with many quotes (""""")
and up to two sequential apostrophes ('').'''^^xsd:string .
Note: Previously we were able to parse multi-line literals. But it seems like now we cannot. Check example 1
and example 2
.
So that the package can parse multi-line literals.
Description and screenshots
When we want to merge two graphs together, or find out the differences between two graphs, it's useful to do that using set operations. We can add some basic methods in the Graph
class to achieve similar results.
Just found out that in the encryption/decryption process, the methods use the hashed key as the real key, and this key is actually stored in the encrypted .enc.ttl
file in plaintext. This is not right. The right way to do it is to use the original key, but needs to find a way to convert different length to a fixed 32-long in order to use AES
.
When the turtle file contains :
or @base
in the namespace prefixes, they'll be ignored in current RDFLib implementation. Need to save them in the graph, and parse and serialize correctly in the Graph
class.
If an ontology contains a property with a range whose value is a List rather than String, Graph._saveToGroups()
fails on line 614 because the for loop casts the range item to a String. I tried changing this to cast to a var
, but I'm not then sure how Graph.item()
should handle it or how the resulting item should be saved to groups
. Below are a sample ontology file to reproduce this (in .ttl and .xml, but both with extra .txt extensions to allow upload), and the Python file used to generate the ontology.
Ontology files to reproduce error (with extra .txt extension to allow upload):
Turtle: rdflib-test.ttl.txt
XML version for info: rdflib-test.xml.txt
Python used to generate ontology files:
import owlready2 as owl
import rdflib as rdf
onto_path = 'https://example.com/rdflib-test#'
onto = owl.get_ontology('https://example.com/rdflib-test')
with onto:
class Object(owl.Thing):
pass
class Mass(owl.DataProperty):
domain = [Object]
range = [owl.ConstrainedDatatype(base_datatype=float, min_exclusive=0.0)]
class has_mass(owl.DataProperty, owl.FunctionalProperty, Object >> Mass):
pass
# Save the resulting ontology
file_name = 'rdflib-test'
onto.save(file=f'{file_name}.xml', format="rdfxml") # save temporary XML that can be read by RDFlib
# Use RDFlib to parse XML ontology and save to TTL
g = rdf.Graph() # an RDFlib graph
g.parse(f'{file_name}.xml') # parse temporary XML into RDFlib graph
g.bind('rdflib-test', rdf.Namespace(onto_path))
g.serialize(f'{file_name}.ttl', format='turtle') # also save TTL locally
# os.remove(f'{owl_file_name}.xml') # delete temporary XML
Based on python package:
https://rdflib.readthedocs.io/en/stable/plugin_parsers.html
Update the graph.parse method.
Add properties such as:
g.value
to find out any triple that has a single rdf:value
g.subjects
to extract all subjects in the graphg.predicates
g.objects
It's a better practice to adopt CI/CD workflows early in developing a package.
Currently there's already some GitHub actions setup in the pods project, e.g., https://github.com/anusii/pods/blob/main/.github/workflows/dart.yml.
Also refer to https://docs.github.com/en/actions/quickstart for a jump start.
For even more complicated grammar rules, I find it hard and messy to process the parsed result with just terminal and combinator parsers (see #11 ).
One step further is to use built-in class GrammarDefinition
in petitparser. The advantage is that I can dissect the bigger problem of parsing the whole turtle file with tens of rules into smaller chunks. GrammarDefinition
gives us a way to build small blocks one by one, and we can extend different expression definitions by customizing the specific production actions.
This also has synergy with the already written classes in the rdflib
package in the way that we can use the methods already there to evaluate the parsed results.
For a Trust No ONe context, allow optional encryption key argument to parse() and serialise() to decrypt/encrypt.
Perhaps use ttc
for encrypted ttl
files.
Refer to Effective Dart: Documentation for best practice.
In addition to read ttl
data from a file, we should also be able to parse long string which is read into memory/variable. This is useful for Indi app which we get the full long text string from the http respond body.
Update the files in the example
folder in the package, also as recommended, include some examples in the code comments.
Review the current API and propose new API that will support common RDF operations that we have used throughout our flutter apps.
So that we can have a simplified interface to make it really easy for the flutter app developer to process RDF data.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.