Skip to content
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

Zy/16 rdflib read remote turtle #45

Merged
merged 22 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions example/example_5.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dart:io';

import 'package:rdflib/rdflib.dart';

main() async {
String filePath = 'example/sample_ttl_5.ttl';
// Read file content to a local String
String fileContents = await File(filePath).readAsStringSync();

print('-------Original file-------\n$fileContents');

// create a graph to read turtle file and store info
Graph g = Graph();

// Parse with the new method [Graph.parseTurtle] instead of [Graph.parse] (deprecated)
g.parseTurtle(fileContents);

// Serialize the Graph for output
g.serialize(format: 'ttl', abbr: 'short');
print('-------Serialized String--------\n${g.serializedString}');

// Print out full format of triples (will use shorthand in serialization/export)
print('--------All triples in the graph-------');
for (Triple t in g.triples) {
print(t);
}
}
21 changes: 21 additions & 0 deletions example/example_6.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:rdflib/rdflib.dart';

main() async {
String webLink = 'https://www.w3.org/TR/turtle/examples/example3.ttl';

// Create a graph to read Turtle file and store info.
Graph g = Graph();

// Parse the Turtle file from the web.
await g.parseTurtleFromWeb(webLink);

// Serialize the Graph for output.
g.serialize(format: 'ttl', abbr: 'short');
print('-------Serialized String--------\n${g.serializedString}');

// Print out full format of triples (will use shorthand in serialization/export).
print('--------All triples in the graph-------');
for (Triple t in g.triples) {
print(t);
}
}
10 changes: 8 additions & 2 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ main() {

// Print out each person's mailbox value
print('-------\nMailboxes:');
for (var sub in g.subjects(a, FOAF.Person)) {
for (var mbox in g.objects(sub, FOAF.mbox)) {
for (var sub in g.subjects(pre: a, obj: FOAF.Person)) {
for (var mbox in g.objects(sub: sub, pre: FOAF.mbox)) {
print('${sub}\'s mailbox: ${mbox.value}');
}
}

// Print out predicates of triples having donna
print('-------\nDonna predicates values:');
for (Triple tri in g.matchTriples(donna.value)) {
print(tri.pre.value);
}
}
20 changes: 20 additions & 0 deletions example/sample_ttl_5.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@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.
Loading
Loading