-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check for undefined, not falsy
- Loading branch information
Showing
7 changed files
with
323 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
_:df_9_1 <https://w3id.org/sds#payload> <http://marineregions.org/mrgid/3959?t=1104534000> <https://w3id.org/sds#DataDescription> . | ||
_:df_9_1 <https://w3id.org/sds#stream> <http://example.org/ns#BenchmarkStream> <https://w3id.org/sds#DataDescription> . | ||
_:df_9_1 <https://w3id.org/sds#bucket> <> <https://w3id.org/sds#DataDescription> . | ||
<http://marineregions.org/mrgid/3959?t=1104534000> <http://purl.org/dc/terms/isVersionOf> <http://marineregions.org/mrgid/3959> . | ||
<http://marineregions.org/mrgid/3959?t=1104534000> <http://purl.org/dc/terms/modified> "2004-03-01T23:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . | ||
<http://marineregions.org/mrgid/3959> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://marineregions.org/ns/ontology#MRGeoObject> . | ||
<http://marineregions.org/mrgid/3959> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://marineregions.org/ns/placetypes#Canyons> . | ||
<http://marineregions.org/mrgid/3959> <http://marineregions.org/ns/ontology#isPartOf> <http://marineregions.org/mrgid/4279> . | ||
<http://marineregions.org/mrgid/3959> <http://purl.org/dc/terms/modified> "2004-03-01T23:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . | ||
<http://marineregions.org/mrgid/3959> <http://www.w3.org/2004/02/skos/core#exactMatch> <urn:acuf:ufi:45863> . | ||
<http://marineregions.org/mrgid/3959> <http://www.w3.org/2004/02/skos/core#note> ": Named after Skikda city"@en . | ||
<http://marineregions.org/mrgid/3959> <http://www.w3.org/2004/02/skos/core#note> ": Removed from GEBCO gazetteer 2010"@en . | ||
<http://marineregions.org/mrgid/3959> <http://www.w3.org/2004/02/skos/core#note> "Coordinates in ACUF: Latitude: 37.133333; Longitude: 6.783333"@en . | ||
<http://marineregions.org/mrgid/3959> <http://www.w3.org/2004/02/skos/core#prefLabel> "Skikda Canyons"@en . | ||
<http://marineregions.org/mrgid/3959> <http://www.w3.org/ns/dcat#centroid> "<http://www.opengis.net/def/crs/OGC/1.3/CRS84> POINT (6.78333333 37.13333333)"^^<http://www.opengis.net/ont/geosparql#wktLiteral> . | ||
<http://marineregions.org/mrgid/3959> <http://www.w3.org/ns/prov#hadPrimarySource> <http://www.ngdc.noaa.gov/gazetteer/> . | ||
<urn:acuf:ufi:45863> <https://schema.org/identifier> _:b5_n3-69958 . | ||
<urn:acuf:ufi:45863> <https://schema.org/url> <https://geonames.nga.mil/arcgis/rest/services/Research/GeoNames/MapServer/0/query?where=UNIQUE_FEATURE_IDENTIFIER_UFI%3D45863> . | ||
_:b5_n3-69958 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://schema.org/PropertyValue> . | ||
_:b5_n3-69958 <https://schema.org/propertyID> <http://www.wikidata.org/entity/P2326> . | ||
_:b5_n3-69958 <https://schema.org/value> "45863" . | ||
<> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://w3id.org/sds#Bucket> <https://w3id.org/sds#DataDescription> . | ||
<> <https://w3id.org/sds#immutable> "false" <https://w3id.org/sds#DataDescription> . | ||
<> <https://w3id.org/sds#isRoot> "true" <https://w3id.org/sds#DataDescription> . | ||
<> <https://w3id.org/sds#stream> <http://example.org/ns#BenchmarkStream> <https://w3id.org/sds#DataDescription> . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { describe, expect, test } from "vitest"; | ||
import { readFile } from "fs/promises"; | ||
import type * as RDF from "@rdfjs/types"; | ||
import { RDF as RDFT, RelationType, SDS } from "@treecg/types"; | ||
import { Parser } from "n3"; | ||
|
||
import { extractShapes, match, subject } from "../../../src/index"; | ||
|
||
export type Record = { | ||
stream: string; | ||
payload: string; | ||
buckets: string[]; | ||
dataless?: boolean; | ||
}; | ||
|
||
export type Bucket = { | ||
id: string; | ||
streamId: string; | ||
immutable?: boolean; | ||
root?: boolean; | ||
empty?: boolean; | ||
}; | ||
|
||
export type RdfThing = { | ||
id: RDF.Term; | ||
quads: RDF.Quad[]; | ||
}; | ||
|
||
export type Relation = { | ||
type: RelationType; | ||
stream: string; | ||
origin: string; | ||
bucket: string; | ||
value?: RdfThing; | ||
path?: RdfThing; | ||
}; | ||
|
||
async function setupLenses() { | ||
const shape_str = await readFile(__dirname + "/shape.ttl", { | ||
encoding: "utf8", | ||
}); | ||
const Shapes = extractShapes(new Parser().parse(shape_str)); | ||
console.log(Shapes); | ||
const RecordLens = match(undefined, SDS.terms.payload, undefined) | ||
.thenAll(subject) | ||
.thenSome(Shapes.lenses["Record"]); | ||
|
||
const BucketLens = match( | ||
undefined, | ||
RDFT.terms.type, | ||
SDS.terms.custom("Bucket"), | ||
) | ||
.thenAll(subject) | ||
.thenSome(Shapes.lenses["Bucket"]); | ||
|
||
const RelationLens = match( | ||
undefined, | ||
RDFT.terms.type, | ||
SDS.terms.custom("Relation"), | ||
) | ||
.thenAll(subject) | ||
.thenSome(Shapes.lenses["Relation"]); | ||
|
||
return { RecordLens, BucketLens, RelationLens }; | ||
} | ||
|
||
async function getData() { | ||
const data_str = await readFile(__dirname + "/data.ttl", { | ||
encoding: "utf8", | ||
}); | ||
const quads = new Parser().parse(data_str); | ||
|
||
return quads.filter((q) => | ||
q.graph.equals(SDS.terms.custom("DataDescription")), | ||
); | ||
} | ||
|
||
describe("test empty ids get extracted", async () => { | ||
const lenses = await setupLenses(); | ||
const data = await getData(); | ||
|
||
test("Records get extracted", () => { | ||
const records = <Record[]>lenses.RecordLens.execute(data); | ||
|
||
expect(records.length).toBe(1); | ||
expect(records[0].buckets.length).toBe(1); | ||
}); | ||
test("Records get extracted", () => { | ||
const buckets = <Bucket[]>lenses.BucketLens.execute(data); | ||
expect(buckets.length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
@prefix cidoc: <http://www.cidoc-crm.org/cidoc-crm/>. | ||
@prefix rdfl: <https://w3id.org/rdf-lens/ontology#>. | ||
@prefix sosa: <http://www.w3.org/ns/sosa/>. | ||
@prefix dcterms: <http://purl.org/dc/terms/>. | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. | ||
@prefix sh: <http://www.w3.org/ns/shacl#>. | ||
@prefix sds: <https://w3id.org/sds#>. | ||
|
||
[ ] a sh:NodeShape; | ||
sh:targetClass <Record>; | ||
sh:property [ | ||
sh:name "stream"; | ||
sh:path sds:stream; | ||
sh:datatype xsd:string; | ||
sh:minCount 1; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "payload"; | ||
sh:path sds:payload; | ||
sh:datatype xsd:string; | ||
sh:minCount 1; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "buckets"; | ||
sh:path sds:bucket; | ||
sh:datatype xsd:string; | ||
], [ | ||
sh:name "dataless"; | ||
sh:path sds:dataless; | ||
sh:datatype xsd:boolean; | ||
sh:minCount 0; | ||
sh:maxCount 1; | ||
]. | ||
|
||
[ ] a sh:NodeShape; | ||
sh:targetClass <Bucket>; | ||
sh:property [ | ||
sh:name "id"; | ||
sh:path ( ); | ||
sh:datatype xsd:string; | ||
sh:minCount 1; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "streamId"; | ||
sh:path sds:stream; | ||
sh:datatype xsd:string; | ||
sh:minCount 1; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "immutable"; | ||
sh:path sds:immutable; | ||
sh:datatype xsd:boolean; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "root"; | ||
sh:path sds:isRoot; | ||
sh:datatype xsd:boolean; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "empty"; | ||
sh:path sds:empty; | ||
sh:datatype xsd:boolean; | ||
sh:maxCount 1; | ||
]. | ||
|
||
[ ] a sh:NodeShape; | ||
sh:targetClass <Relation>; | ||
sh:property [ | ||
sh:name "type"; | ||
sh:path sds:relationType; | ||
sh:datatype xsd:string; | ||
sh:minCount 1; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "stream"; | ||
sh:path ( [ sh:inversePath sds:relation ] sds:stream ); | ||
sh:datatype xsd:string; | ||
sh:minCount 1; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "origin"; | ||
sh:path [ sh:inversePath sds:relation ]; | ||
sh:datatype xsd:string; | ||
sh:minCount 1; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "bucket"; | ||
sh:path sds:relationBucket; | ||
sh:datatype xsd:string; | ||
sh:minCount 1; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "path"; | ||
sh:path sds:relationPath; | ||
sh:class <RdfThing>; | ||
sh:maxCount 1; | ||
], [ | ||
sh:name "value"; | ||
sh:path sds:relationValue; | ||
sh:class <RdfThing>; | ||
sh:maxCount 1; | ||
]. | ||
|
||
[ ] a sh:NodeShape; | ||
sh:targetClass <RdfThing>; | ||
sh:property [ | ||
sh:name "id"; | ||
sh:path ( ); | ||
sh:maxCount 1; | ||
sh:minCount 1; | ||
sh:datatype xsd:any; | ||
], [ | ||
sh:name "quads"; | ||
sh:path ( ); | ||
sh:maxCount 1; | ||
sh:minCount 1; | ||
sh:class rdfl:CBD; | ||
]. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { readFile } from "fs/promises"; | ||
import type * as RDF from "@rdfjs/types"; | ||
import { RDF as RDFT, RelationType, SDS } from "@treecg/types"; | ||
import { Parser } from "n3"; | ||
|
||
import { extractShapes, match, subject } from "../../../src/index"; | ||
|
||
export type Record = { | ||
stream: string; | ||
payload: string; | ||
buckets: string[]; | ||
dataless?: boolean; | ||
}; | ||
|
||
export type Bucket = { | ||
id: string; | ||
streamId: string; | ||
immutable?: boolean; | ||
root?: boolean; | ||
empty?: boolean; | ||
}; | ||
|
||
export type RdfThing = { | ||
id: RDF.Term; | ||
quads: RDF.Quad[]; | ||
}; | ||
|
||
export type Relation = { | ||
type: RelationType; | ||
stream: string; | ||
origin: string; | ||
bucket: string; | ||
value?: RdfThing; | ||
path?: RdfThing; | ||
}; | ||
|
||
async function setupLenses() { | ||
const shape_str = await readFile("/shape.ttl", { encoding: "utf8" }); | ||
const Shapes = extractShapes(new Parser().parse(shape_str)); | ||
const RecordLens = match(undefined, SDS.terms.payload, undefined) | ||
.thenAll(subject) | ||
.thenSome(Shapes.lenses["Record"]); | ||
|
||
const BucketLens = match( | ||
undefined, | ||
RDFT.terms.type, | ||
SDS.terms.custom("Bucket"), | ||
) | ||
.thenAll(subject) | ||
.thenSome(Shapes.lenses["Bucket"]); | ||
|
||
const RelationLens = match( | ||
undefined, | ||
RDFT.terms.type, | ||
SDS.terms.custom("Relation"), | ||
) | ||
.thenAll(subject) | ||
.thenSome(Shapes.lenses["Relation"]); | ||
|
||
return { RecordLens, BucketLens, RelationLens }; | ||
} | ||
|
||
async function getData() { | ||
const data_str = await readFile("/data.ttl", { encoding: "utf8" }); | ||
const quads = new Parser().parse(data_str); | ||
|
||
return quads.filter((q) => | ||
q.graph.equals(SDS.terms.custom("DataDescription")), | ||
); | ||
} | ||
|
||
describe("test empty ids get extracted", async () => { | ||
const lenses = await setupLenses(); | ||
const data = await getData(); | ||
|
||
test("Records get extracted", () => { | ||
const records = <Record[]>lenses.RecordLens.execute(data); | ||
console.log(records); | ||
expect(2).toBe(4); | ||
}); | ||
const buckets = <Bucket[]>lenses.BucketLens.execute(data); | ||
}); |