Skip to content

Commit

Permalink
Supporting literals in subject position
Browse files Browse the repository at this point in the history
  • Loading branch information
phochste committed Jun 16, 2023
1 parent 67653a6 commit 4a4d483
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
2023-06-16 0.0.2
- Supporting variables
- Supporting literals in subject position

2023-06-16 0.0.1
- Initial release
52 changes: 30 additions & 22 deletions data/00-simple.n3
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,36 @@

:Person :is :test .
true :is :test .
:false :is :test .
# "blue ball" :is :test . N3 NOT SUPPORTED
false :is :test .
"blue ball"^^xsd:string :is :test . # see https://github.com/rdfjs/N3.js/issues/328
123 :is :test .
"3.14"^^xsd:float :is :test .
_:x :is :test .
?x :is :test .

#:test :is () .
#:test :is ( :Red :Green :Blue ) .
#:test :is ( :Red (:Green 123) :Blue ) .
#() :is :Red .
#() :is (:Red :Blue).
#_:x a :Color .
#(_:x) a :Color .
#(12 _:x) a :Color .
#(:Red :Blue) a :Color .
#[] a [ a :Color ].
#{ :a :b :c } a :Graph .
#{ :a :b :c . :d :e :f } a :Graph .
#(_:x) log:onNegativeSurface {
# :a :b _:x .
# () log:onNegativeSurface {
# :c a _:x .
# } .
#} .

#:Alice :thinks { :Bob :is :Smoking } .
:is :Person :test .
#:is true :test . # see https://github.com/rdfjs/N3.js/issues/328
#:is false :test .
#:is "blue ball"^^xsd:string :test .
#:is 123 :test .
#:is "3.14"^^xsd:string :test .
#:is _:x :test . # NOT SUPPORTED YET
#:is ?x :test. # NOT SUPPORTED YE

:test :is () .
:test :is ( :Red :Green :Blue ) .
:test :is ( :Red (:Green 123) :Blue ) .

() :is :test .
( :Red :Green :Blue ) :is :test .
( :Red (:Green 123) :Blue ) :is :test .

#:is () :test . # not supported in n3
#:is ( :Red :Green :Blue ) :test .
#:is ( :Red (:Green 123) :Blue ) :test.

:test :is { :a :b :c } .
{ :a :b :c } :is :test .
# :is { :a :b :c } :test . # not supported in n3

{ :a :b ?x } :is { ?x :d :e } .
9 changes: 5 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function parseN3File(file: string) : Promise<N3.Store> {
}

export async function parseN3(n3: string) : Promise<N3.Store> {
const parser = new N3.Parser({ format: 'Notation3' });
const parser = new N3.Parser({ format: 'text/n3' });

const store = new N3.Store();

Expand Down Expand Up @@ -168,8 +168,8 @@ export function makeGraph(store: N3.Store, graph: N3.Term = N3.DataFactory.defau

// First process the named nodes...
store.forEach((quad) => {
if ((quad.subject.termType === 'NamedNode' ||
quad.subject.termType === 'Variable')
const termType = '' + quad.subject.termType;
if ((termType === 'NamedNode' || termType === 'Literal' || termType === 'Variable')
&& !isGraphLike(quad,graph)) {
let subject = parseTerm(quad.subject, store);
let predicate = parseTerm(quad.predicate, store);
Expand All @@ -185,7 +185,8 @@ export function makeGraph(store: N3.Store, graph: N3.Term = N3.DataFactory.defau

// Next process the explicit bnodes...
store.forEach((quad) => {
if (quad.subject.termType === 'BlankNode'
const termType = '' + quad.subject.termType;
if (termType === 'BlankNode'
&& !isListLike(quad)
&& !isGraphLike(quad,graph)) {
let subject = parseTerm(quad.subject, store);
Expand Down

0 comments on commit 4a4d483

Please sign in to comment.