parseTTLStr function
- String ttlStr
Parse TTL string ttlStr
and returns the key-value pairs from triples where
Subject: Web ID Predicate: Key Object: Value
Implementation
Future<List<({String key, dynamic value})>> parseTTLStr(String ttlStr) async {
assert(ttlStr.isNotEmpty);
final g = Graph();
g.parseTurtle(ttlStr);
final keys = <String>{};
final pairs = <({String key, dynamic value})>[];
final webId = await getWebId();
assert(webId != null);
String extract(String str) => str.contains('#') ? str.split('#')[1] : str;
for (final t in g.triples) {
final sub = t.sub.value as String;
if (sub == webId) {
final pre = extract(t.pre.value as String);
final obj = extract(t.obj.value as String);
assert(!keys.contains(pre));
keys.add(pre);
pairs.add((key: pre, value: obj));
}
}
return pairs;
}