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

Generate types for external schema #169

Open
hawyar opened this issue Feb 10, 2022 · 10 comments
Open

Generate types for external schema #169

hawyar opened this issue Feb 10, 2022 · 10 comments

Comments

@hawyar
Copy link

hawyar commented Feb 10, 2022

I am trying to generate types for the GS1 web vocabulary. I have included the context used

schema-dts-gen --ontology=https://schema.org/version/latest/schemaorg-all-https.nt --context=cc:http://creativecommons.org/ns#,cert:http://www.w3.org/ns/auth/cert#,dbp:http://dbpedia.org/property/,dc:http://purl.org/dc/elements/1.1/,dcterms:http://purl.org/dc/elements/1.1/,doap:http://usefulinc.com/ns/doap#,exif:http://www.w3.org/2003/12/exif/ns#,fn:http://www.w3.org/2005/xpath-functions#,foaf:http://xmlns.com/foaf/0.1/,geo:http://www.w3.org/2003/01/geo/wgs84_pos#,geonames:http://www.geonames.org/ontology#,gr:http://purl.org/goodrelations/v1#,gs1:https://gs1.org/voc/,log:http://www.w3.org/2000/10/swap/log#,owl:http://www.w3.org/2002/07/owl#,rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#,rdfs:http://www.w3.org/2000/01/rdf-schema#,rei:http://www.w3.org/2004/06/rei#,rsa:http://www.w3.org/ns/auth/rsa#,rss:http://purl.org/rss/1.0/,schema:http://schema.org/,sfn:http://www.w3.org/ns/sparql#,sioc:http://rdfs.org/sioc/ns#,skos:http://www.w3.org/2004/02/skos/core#,sw:http://www.w3.org/2003/06/sw-vocab-status/ns#,swrc:http://swrc.ontoware.org/ontology#,types:http://rdfs.org/sioc/types#,vann:http://purl.org/vocab/vann/,vcard:http://www.w3.org/2006/vcard/ns#,voaf:http://purl.org/vocommons/voaf#,wot:http://xmlns.com/wot/0.1/,xhtml:http://www.w3.org/1999/xhtml#,xsd:http://www.w3.org/2001/XMLSchema# > schema.ts

which results in the correct context

export type WithContext<T extends Thing> = T & {
    "@context": {
        "cc": "http://creativecommons.org/ns#";
        "cert": "http://www.w3.org/ns/auth/cert#";
        "dbp": "http://dbpedia.org/property/";
        "dc": "http://purl.org/dc/elements/1.1/";
        "dcterms": "http://purl.org/dc/elements/1.1/";
        "doap": "http://usefulinc.com/ns/doap#";
        "exif": "http://www.w3.org/2003/12/exif/ns#";
        "fn": "http://www.w3.org/2005/xpath-functions#";
        "foaf": "http://xmlns.com/foaf/0.1/";
        "geo": "http://www.w3.org/2003/01/geo/wgs84_pos#";
        "geonames": "http://www.geonames.org/ontology#";
        "gr": "http://purl.org/goodrelations/v1#";
        "gs1": "https://gs1.org/voc/";
        "log": "http://www.w3.org/2000/10/swap/log#";
        "owl": "http://www.w3.org/2002/07/owl#";
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
        "rdfs": "http://www.w3.org/2000/01/rdf-schema#";
        "rei": "http://www.w3.org/2004/06/rei#";
        "rsa": "http://www.w3.org/ns/auth/rsa#";
        "rss": "http://purl.org/rss/1.0/";
        "schema": "http://schema.org/";
        "sfn": "http://www.w3.org/ns/sparql#";
        "sioc": "http://rdfs.org/sioc/ns#";
        "skos": "http://www.w3.org/2004/02/skos/core#";
        "sw": "http://www.w3.org/2003/06/sw-vocab-status/ns#";
        "swrc": "http://swrc.ontoware.org/ontology#";
        "types": "http://rdfs.org/sioc/types#";
        "vann": "http://purl.org/vocab/vann/";
        "vcard": "http://www.w3.org/2006/vcard/ns#";
        "voaf": "http://purl.org/vocommons/voaf#";
        "wot": "http://xmlns.com/wot/0.1/";
        "xhtml": "http://www.w3.org/1999/xhtml#";
        "xsd": "http://www.w3.org/2001/XMLSchema#";
    };
};

but then I am not sure how to use

const product: WithContext<Product> 

I think I am missing something here. Any feedback is appreciated

@Eyas
Copy link
Collaborator

Eyas commented Feb 11, 2022

Hmm. You'll need a few things to do this:

  1. Point --ontology to a NTriple format version of this schema. You might find a converter that transforms "GS1 Web vocabulary in RDF Turtle" to .nt

  2. GS1 appears to extend OWL, and the base type in owl, "Thing". Needs to be included as part of the ontology you pass. I had plans on supporting passing multiple ontologies but we didn't have an immediate need yet

I vaguely remember running into some issues last time I looked at passing the owl definitions because they utilized a richer set of RDF, including anonymous lists, etc, which this parser didn't understand. But I might be mixing this up.

Let me know how it goes. You can try to get something locally by converting .tt or JSON-LD schema definitions of both into .nt, saving both to disk and concatenating both files.

I'll try to set some time aside in the next few days to reproduce myself.

@Eyas
Copy link
Collaborator

Eyas commented Feb 11, 2022

When it works, btw, you would see the properties of Product include "gs1:additionalProductDescription" etc

@hawyar
Copy link
Author

hawyar commented Feb 16, 2022

Thanks for the lead. I have both schema definitions in .nt format (https://github.com/hawyar/gs1.nt). Now using gs1.nt for the --ontology throws this error which I think is similar to what you mentioned.

Caught Error on end: Error: ParseError: Error: Unexpected URL http://gs1.org/voc/ with no room for 'name'. while parsing line http://gs1.org/voc/,http://purl.org/dc/elements/1.1/description,"The GS1 RDF vocabulary, described using W3C RDF Schema and the Web Ontology Language.".
Original Stack:
Error: Unexpected URL http://gs1.org/voc/ with no room for 'name'.
    at Function.Parse (file:///Users/hawyar/Personal/gs1-schema/node_modules/schema-dts-gen/dist/src/triples/types.js:88:19)
    at subject (file:///Users/hawyar/Personal/gs1-schema/node_modules/schema-dts-gen/dist/src/triples/reader.js:32:20)
    at process (file:///Users/hawyar/Personal/gs1-schema/node_modules/schema-dts-gen/dist/src/triples/reader.js:172:26)
    at process.next (<anonymous>)
    at IncomingMessage.<anonymous> (file:///Users/hawyar/Personal/gs1-schema/node_modules/schema-dts-gen/dist/src/triples/reader.js:119:28)
    at IncomingMessage.emit (node:events:532:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

Is the richer set of RDF in the GS1 schema definition the main issue here? I would be happy to dedicate some time for this.

@Eyas
Copy link
Collaborator

Eyas commented Feb 16, 2022

I thought a richer set of RDF would be present in OWL (which exercises blank nodes), but in this case it appears that schema-dts might not need to care about this.

The parse error here is due to references to <http://gs1.org/voc/>. To refer to a node in a "shortened" way (e.g. via context), it typically needs a hash part or trailing path (after last /). schema-dts should probably be more open-minded, and support a "Full URL-only" node, which can only be referenced using a complete URL.

In this specific case these are meta-properties that likely won't affect your output TS anyway.

Once that is done, you'll still see another issue: gs1 uses http://www.w3.org/2002/07/owl# to describe types and properties of objects. We need better awareness that an OWL class behaves the same(ish) as an rdfa class.

@Eyas
Copy link
Collaborator

Eyas commented Feb 23, 2022

I'm looking into fixing this, but FWIW gs1's generated schema seems to be invalid. E.g.

MeasurementPrecisionCode-LESS_THAN is a sub-type of MeasurementPrecisionTypeCode, but no such class exists (it's a typo, supposed to be MeasurementPrecisionCode.

So until gs1 fixes their code, you'll always need manual modifications on top of the generated .nt file.

Eyas added a commit to Eyas/schema-dts that referenced this issue Feb 23, 2022
1. Support URL nodes with no "name"
2. Support URL nodes with search query string
3. Understand native rdfs:domain and rdfs:range directives
4. Do not treat OWL Class/Property & other ontology declarations as enum
   membership
5. Context support for unnamed URLs ("schema:" is totally valid)
6. Allow type=Class to be transitive
7. Support 1-char long strings

This begins building support for google#169
@hawyar
Copy link
Author

hawyar commented Feb 25, 2022

I am having difficulty understating the rdfa and owl class clash here.

I can fix the typo in the generated .nt file. Is that whyMeasurementPrecisionCode-LESS_THAN is listed in the spec but is not in https://www.gs1.org/voc/MeasurementPrecisionCode ?

Thank you

@Eyas
Copy link
Collaborator

Eyas commented Feb 25, 2022

That's likely. And yeah fixing the typo for MeasurementPrecisionCode will help. There are a few others that are also broken. I'll try to regenerate a list.

I am having difficulty understating the rdfa and owl class clash here.

Can you elaborate?

@hawyar
Copy link
Author

hawyar commented Feb 25, 2022

No worries, just a knowledge gap on my part. I was trying to understand "We need better awareness that an OWL class behaves the same(ish) as an rdfa class"

How did you catch the typo?

@Eyas
Copy link
Collaborator

Eyas commented Feb 25, 2022

I ran schema-dts-gen 1.1.0 (or the equivalent local version I was using) against the .nt you provided, and every time it complained about an error I noted it

@Eyas
Copy link
Collaborator

Eyas commented Feb 25, 2022

I also commented on consensusnetworks/healthnet#104 that the context you're using there is not quite right (yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants