Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b883b0d
Update README.md
weasdown Jun 17, 2024
1cd23b4
Update README.md
weasdown Jun 17, 2024
9297144
Update README.md
weasdown Jun 17, 2024
4aa33cd
Added initial String/List branching
weasdown Jun 18, 2024
f4ddd3d
Added itemFromList() to handle obj being a List
weasdown Jun 18, 2024
7ed1300
Added first version of parser to itemFromList()
weasdown Jun 18, 2024
afac50d
Improved handling of brackets
weasdown Jun 18, 2024
3662a11
Fixed bracket handling
weasdown Jun 18, 2024
1159604
Removed print
weasdown Jun 18, 2024
ce32dc2
Started adding parsing for multiple ConstrainedDatatype restrictions
weasdown Jun 23, 2024
fd195ff
Improved handling of pre and multi-value objects
weasdown Jun 23, 2024
664a30c
Neatened parsing of multi-attribute objects
weasdown Jun 23, 2024
94cd210
Removed commented code, fixed excess Set layer
weasdown Jun 23, 2024
48eace9
Merge branch 'anusii:main' into main
weasdown Jun 26, 2024
24bc15b
Update graph.dart to make deep list work
zheyxu Jul 2, 2024
2876b5b
Merge pull request #1 from zheyxu/patch-1
weasdown Jul 2, 2024
4267fec
Add rdflib-proto
weasdown Jul 21, 2024
d07fae6
Reset README.md
weasdown Aug 1, 2024
f13784f
Merge branch 'zy/46_parsing_nested_liberals' into main
zheyxu Aug 2, 2024
8e70943
Merge pull request #50 from weasdown/main
zheyxu Aug 2, 2024
cbc55e1
Merge remote-tracking branch 'origin/main' into zy/46_parsing_nested_…
zheyxu Aug 13, 2024
bc924a8
[#52] Fix parsing of semicolon at end of predicateObjectList
tristantarrant Mar 25, 2025
4a328b1
Merge pull request #53 from tristantarrant/52/fix_semicolon_end_plist
zheyxu Apr 14, 2025
2d250ea
dart format
zheyxu Apr 14, 2025
3a76079
update comments
zheyxu Apr 14, 2025
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
5 changes: 3 additions & 2 deletions lib/parser/grammar_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class ExpressionDefinition extends GrammarDefinition {
Parser turtleDoc() => ref0(statement).star();
}

/// This class focuses on interpreting and formatting the raw parsed data
/// This class focuses on interpreting and formatting the raw parsed data
/// into a more structured and meaningful format.

class EvaluatorDefinition extends ExpressionDefinition {
Expand Down Expand Up @@ -337,7 +337,8 @@ class EvaluatorDefinition extends ExpressionDefinition {
rtnList.add(firstPreObj);
final restPreObjs = values[2] as List;
for (var i = 0; i < restPreObjs.length; i++) {
rtnList.add(restPreObjs[i][1][0]);
var o = restPreObjs[i][1] as List;
if (o.length > 0) rtnList.add(o[0]);
}
return rtnList;
});
Expand Down
153 changes: 146 additions & 7 deletions lib/src/graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import 'dart:io' show File;
import 'package:http/http.dart' as http;
import 'package:universal_io/io.dart' show Platform;

import './namespace.dart';
import 'namespace.dart';
import './term.dart';
import './triple.dart';
import './constants.dart';
import 'triple.dart';
import 'constants.dart';
import '../parser/grammar_parser.dart';

class Graph {
Expand Down Expand Up @@ -787,12 +787,35 @@ class Graph {
dynamic pre = item(predicateObjectList[0]);
groups[sub]![pre] = Set();
List objectList = predicateObjectList[1];

for (var obj in objectList) {
var parsedObj =
(obj is List) ? item(_combineListItems(obj)) : item(obj);
groups[sub]![pre]!.add(parsedObj);
triples.add(Triple(sub: sub, pre: pre, obj: parsedObj));
var objItem;
if (obj is String) {
objItem = item(obj);
} else if (obj is List) {
objItem = itemFromList(obj);
}

groups[sub]![pre]!.add(objItem);
triples.add(Triple(sub: sub, pre: pre, obj: objItem));

/// Keep it for future use.

// for (var obj in objectList) {
// var parsedObj =
// (obj is List) ? item(_combineListItems(obj)) : item(obj);
// groups[sub]![pre]!.add(parsedObj);
// triples.add(Triple(sub: sub, pre: pre, obj: parsedObj));
// }
}

/// Keep it for future use.

// // Original for loop - TODO remove
// for (String obj in objectList) {
// groups[sub]![pre]!.add(item(obj));
// triples.add(Triple(sub: sub, pre: pre, obj: item(obj)));
// }
}
}

Expand Down Expand Up @@ -894,6 +917,122 @@ class Graph {
}
}

List stripBrackets(List values) {
if (values[0] == '(' || values[0] == '[') {
values = values.sublist(1, values.length - 1);
}
return values;
}

Set parseObjectValues(List objVals) {
/// Parses a Set or List of multiple object values
objVals = stripBrackets(objVals)[0];

Set values = {};
for (var objVal in objVals) {
if (objVal is List) {
objVal = stripBrackets(objVal)[0][0];

String objName = objVal[0];
List subValues = objVal[1];

// TODO try to parse to int/float etc
Map objMap = {
item(objName): subValues.length == 1
? item(subValues[0])
: subValues.map((e) => item(e)).toSet()
};
values.add(objMap);
} else {
// TODO
values.add(objVal);
}
}
return values;
}

List parseObjectValueFromNameStringAndValueList(List obj) {
/// Used for getting name and values for objects when obj is in the format:
/// ['Object name string', ['Value 1', 'Value 2 (optional)'...] ]
/// Returns in format: {'Object name string': {'Value 1', 'Value 2 (optional)'...} }

String objName = obj[0];

List values = obj[1];
Set objValues = {};

if (values.length == 1) {
objValues.add(values[0]);
} else {
// TODO parse multiple values
// List singleValuesList = values[1];
for (final val in values) {
// check whether string or list
if (val is String) {
objValues.add(val);
} else {
// TODO
throw UnimplementedError(
'Parsing of multiple values is not yet implemented in this method');
}
}
}

return [objName, objValues];
}

parseObjectValue() {
/// Parses a single object value
}

Map<URIRef, Set<dynamic>> itemFromList(List tripleList) {
List predicateObjectLists = [];
Map<URIRef, Set<dynamic>> objectGroups = Map();

if (tripleList[0] == '(') {
if (tripleList[1][0] is List) {
tripleList = tripleList[1][0];
}
}

if (tripleList[0] == '[') {
// trim leading and trailing 'entries' that are just [ or ]
tripleList = tripleList.sublist(1, tripleList.length - 1);
predicateObjectLists = tripleList[0];
}

for (List predicateObjectList in predicateObjectLists) {
if (predicateObjectList[0] == '[') {
predicateObjectList =
predicateObjectList.sublist(1, predicateObjectList.length - 1);
}
var pre;
pre = item(predicateObjectList[0]);
var objValues = predicateObjectList[1];

if (predicateObjectList[0] is List) {
// detect list within predicateObjectList and iterate
pre = itemFromList(predicateObjectList[0]);
} else {
pre = item(predicateObjectList[0]); // URIRef
}

Set objItem = {};

for (final obj in objValues) {
if (objValues[0] is List && objValues[0].length > 1) {
// Multiple object values found (e.g. multiple restrictions on a ConstrainedDatatype)
objItem.add(parseObjectValues(objValues[0]));
} else {
objItem.add(item(obj));
}
}

objectGroups[pre] = objItem;
}
return objectGroups;
}

/// Serializes the graph to certain format and export to file.
///
/// Note:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/namespace.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './term.dart';
import 'term.dart';
import 'constants.dart';

class Namespace {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/term.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:logging/logging.dart';
import 'package:uuid/uuid.dart' as uuid;

import './namespace.dart';
import 'namespace.dart';

Logger logger = Logger('term');

Expand Down