Git Product home page Git Product logo

rdflib's People

Contributors

anushkavidanage avatar gjwgit avatar tian3rd avatar zheyxu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

staylorx weasdown

rdflib's Issues

RDFLIB: Update the solid_auth and rdflib packages to http: 1.1.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

RDFLIB: Exception when parsing the get response of a container

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.

RDF: test `rdfgraph` package with SOLID-Health-Ontology-Example

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:

  • Add data type property
  • Add named individual
  • Add object property
  • Read 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.

RDFLib: use `GrammarDefinition` for all turtle parsers, and extend and evaluate the results of parsing.

  • 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.

It seems following files cannot be parsed using g.parseTurtle() function

@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

RDFLib: complete the terminal/combinator parsers for turtle grammar and have them all tested

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.

RDFLib: Create test files for terminal and combinator parsers using `petitparser`

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.

Parsing nested liberals.

Some turtle formats are not supported by the Rdflib parser. Following are some examples.

Example 1

@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/>
  ] .

Example 2

@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

Parse multi-line literals

User Story

Example 1

@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 .

Example 2

@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.

Why

So that the package can parse multi-line literals.

Closing Criteria

  • [parse multi-line literals]

Details

Description and screenshots

RDF: fix the issue of using encryption/decryption hashed key as the real key for `AES`

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.

  • Convert any key to a unique 32 length key
  • Use this secret key to encrypt and decrypt

RDFLib: fix ':' and '@base' in namespace prefixes

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.

ConstrainedDatatype causes g.parseTurtle failure

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.

image

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

Summary of what has been done and what is the next

What has been done

  1. void parseTurtle(String fileContent) Parses a valid turtle file read into a string [fileContent]. Updates [Graph.ctx], [Graph.groups] and [Graph.triples] in the process.
  2. bool inNamespace(Namespace ns) Checks if a full URIRef contains the namespace.
  3. Set objects(URIRef sub, URIRef pre) Finds all objects which have a certain subject and predicate.
    URIRef withAttr(String attr) This is used to further shorten the namespace binding.
  4. bool addNamedIndividualToGroups(dynamic s) Adds named individual to graph: rdf:type owl:NamedIndividual.
  5. void addTripleToGroups(dynamic s, dynamic p, dynamic o) Adds a triple to group using its string forms.
  6. void addObjectProperty(URIRef obj, URIRef relation, URIRef prop) Adds object property to link two triple subjects together.
  7. void bind(String name, Namespace ns) Binds a namespace to a prefix for better readability when serializing.
  8. void serialize({String format = 'ttl', String? dest, String? abbr}) Serializes the graph to certain format and export to file.

What is the next

  1. Add blank node integration
  2. Delete a triple in the Graph
  3. Matching triples of certain criteria
  4. parseTurtle gives more information of error, such as pointing out which line is the error
  5. SPARQL query integration
  6. Read remote turtle files (e.g. from web link)
  7. Support Graph operations like merging, intersection of different Graphs

RDFLib: Use grammar definitions as building blocks to define grammar rules for turtle

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.

RDFLib: support parsing long text string

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.

Review `rdflib` package

Description

Review the current API and propose new API that will support common RDF operations that we have used throughout our flutter apps.

Why

So that we can have a simplified interface to make it really easy for the flutter app developer to process RDF data.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.