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

@optional bugged #35

Open
renevds opened this issue Jul 12, 2021 · 4 comments
Open

@optional bugged #35

renevds opened this issue Jul 12, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@renevds
Copy link

renevds commented Jul 12, 2021

The following query:

{
      name @single
      image @single
      readMoreUrl @single
      rml @single
      knowledgeGraph @optional @single
}

On the following ttl file:

@prefix ex: <http://example.com/rmlio/> .
@prefix kees: <http://linkeddata.center/kees/v1#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <http://schema.org/> .

<https://rml.io/usecases/BESOCIAL> a ex:useCase;
  ex:rules "https://github.com/RMLio/social-media-archiving/tree/master/mappings";
  schema:description """<a href=\"https://www.kbr.be/en/projects/besocial/\">BESOCIAL</a> is a cross-institutional research project,
aiming to develop a sustainable strategy for archiving and preserving social media in Belgium.
Heterogeneous social media content, provenance information provided by web archivists as well as preservation metadata enclosed in web archive (WARC) files characterize this use case.
A developed <a href=\"https://github.com/RMLio/social-media-archiving\">open source component</a> integrates RML.io into the existing <a href=\"https://gwu-libraries.github.io/sfm-ui/\">Social Feed Manager (SFM)</a> framework from the George Washington University Libraries.
Therefore, RML.io supports data stewardship tasks in a sustainable open source workflow by mapping heterogeneous data on the fly to a knowledge graph.
This use case uses RML rules in <a href=\"https://rml.io/yarrrml/\">YARRRML</a> syntax which are used by a <a href=\"https://github.com/RMLio/rmlmapper-java-wrapper-js\">javascript wrapper</a> of the <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> to generate the knowledge graph.""";
  schema:image "/img/use-cases/besocial.jpg";
  schema:name "BESOCIAL";
  schema:url "https://github.com/RMLio/social-media-archiving" .

<https://rml.io/usecases/Between%20Our%20Worlds> a ex:useCase;
  ex:rules "https://github.com/BetweenOurWorlds/generation-rules";
  kees:KnowledgeGraph "https://data.betweenourworlds.org/latest";
  schema:description "Between Our Worlds is an initiative to provide metadata information about anime as Linked Open Data. It uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is converted to RML, to define how the knowledge graph is generated based on the metadata downloaded from a Web API. <a href=\"https://fno.io/\">FnO</a> is used to transform certain aspects of the original data. The <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> is used to execute the RML rules to generate the knowledge graph.";
  schema:downloadUrl "http://docs.kitsu.apiary.io/";
  schema:image "/img/use-cases/between-our-worlds.png";
  schema:name "Between Our Worlds";
  schema:url "https://betweenourworlds.org" .

<https://rml.io/usecases/COVID%2019%20Knowledge%20Graph> a ex:useCase;
  ex:rules "https://github.com/GillesVandewiele/COVID-KG/tree/master/rml";
  kees:KnowledgeGraph "https://www.kaggle.com/group16/covid19-literature-knowledge-graph";
  schema:description "This use case generates a <a href=\"https://www.kaggle.com/group16/covid19-literature-knowledge-graph\">knowledge graph</a> from the COVID-19 literature. It uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is converted to RML, to define how the knowledge graph is generated based on the metadata of the literature. <a href=\"https://rml.io/yarrrml/matey/\">Matey</a> is used to assist in defining the YARRRML rules and the <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> is used to execute the RML rules to generate the knowledge graph.";
  schema:downloadUrl "https://www.kaggle.com/allen-institute-for-ai/CORD-19-research-challenge";
  schema:image "/img/use-cases/covid-19-kg.jpg";
  schema:name "COVID 19 Knowledge Graph";
  schema:url "https://github.com/GillesVandewiele/COVID-KG" .

<https://rml.io/usecases/European%20Union%20Agency%20for%20Railways> a ex:useCase;
  ex:rules "https://github.com/julianrojas87/era-data-mappings/tree/master/rml";
  kees:KnowledgeGraph "http://era.ilabt.imec.be/query/";
  schema:description "The European Union Agency for Railways (ERA) generates a knowledge graph to foster interoperability across their base registry databases which are populated by all EU member states and different actors from the railway domain. This use case uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is automatically converted to RML, to define how the knowledge graph is generated based on different data sources, such as databases, CSV files, XML files, and so on. The <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> is used to execute the RML rules to generate the knowledge graph, which can be explored and queried online.";
  schema:downloadUrl "https://github.com/julianrojas87/era-data-mappings/tree/master/data";
  schema:image "/img/use-cases/era.jpg";
  schema:name "European Union Agency for Railways";
  schema:url "https://www.era.europa.eu/" .

<https://rml.io/usecases/Montolo> a ex:useCase;
  ex:rules "https://github.com/IDLabResearch/Montolo/blob/master/montolo-raw/montolo.yml";
  kees:KnowledgeGraph "https://w3id.org/montolo/ns/montolo/";
  schema:description """<a href=\"https://w3id.org/montolo\">Montolo</a> is a knowledge graph with the aim to provide FAIR metadata of ontologies to support knowledge modeling tasks such as the assessment and reuse of existing ontologies,
currently existing related datasets are <a href=\"https://doi.org/10.5281/zenodo.3343052\">MontoloStats</a> for ontologies and <a href=\"https://doi.org/10.5281/zenodo.3988929\">MontoloSHACLStats</a> for data shapes.
The Montolo Knowledge Graph is manually curated using CSV files on <a href=\"https://github.com/IDLabResearch/Montolo/tree/master/montolo-raw\">GitHub</a> including an alignment with the <a href=\"https://zenodo.org/record/3626676\">Astrea Knowledge Graph</a>.
This use case uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is automatically converted
to RML, to define how the knowledge graph is generated.
The <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> is used to execute the RML rules to generate the knowledge graph.""";
  schema:downloadUrl "https://github.com/IDLabResearch/Montolo/tree/master/montolo-raw";
  schema:image "/img/use-cases/montolo.jpg";
  schema:name "Montolo";
  schema:url "https://w3id.org/montolo" .

<https://rml.io/usecases/Sollicimeer%20%28Inclusion%20in%204D%29> a ex:useCase;
  schema:description "Sollicimeer is a job application platform for people with a learning disability. Companies provide their job applications using a spreadsheet. It uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is converted to RML, to define how knowledge graphs are generated based on the data in the spreadsheet. Next, each knowledge graph is added to the company's <a href=\"https://solidproject.org/\">Solid POD</a>. When a person wants to apply for a job the relevant application information is read from the POD and during the application the information about the person is stored in their personal POD.";
  schema:image "/img/use-cases/sollicimeer.png";
  schema:name "Sollicimeer (Inclusion in 4D)";
  schema:url "http://hellojennywordpress.azurewebsites.net/index.php/uitdaging-2-solliciteren-met-een-leerstoornis/" .

<https://rml.io/usecases/Velopark> a ex:useCase;
  ex:rules "https://github.com/linkedtimeseries/timeseries-server/tree/develop/mappings";
  schema:description "To facilitate information access to bicycle users about parking infrastructure, Fietsberaad, a pro-cycling organization managed by the Flemish government, worked together with local authorities, parking facility owners and operators in Belgium to design common framework for modeling and publishing (live) information of parking facilities. Existing data and interfaces (APIs) were reused and transformed to a common <a href=\"https://velopark.ilabt.imec.be/openvelopark/vocabulary\">semantic data representation</a> using <a href=\"https://github.com/linkedtimeseries/timeseries-server/tree/develop/mappings\">RML rules</a> in YARRRML syntax. Currently more than 30 municipalities across Belgium publish data of 2500+ parkings, made accessible to cyclists <a href=\"https://velopark.be/\">online</a>.";
  schema:image "/img/use-cases/velopark.png";
  schema:name "Velopark";
  schema:url "https://velopark.be/" .

Returns the correct results.
But when adding an @optional field.
Changing the query to:

{
      name @single
      image @single
      readMoreUrl @single
      rml @single
      rules @optional @single
}

Causes the resultset to shrink, the missing results may or may not have the rules field.
When adding another field to this query like so:

{
	  type (_:useCase)
	  name @single
	  image @single
	  readMoreUrl @single
	  rml @single
	  knowledgeGraph @optional @single
	  rules @optional @single
}

The resultset was suddenly back to what was to be expected.
I have had similar behavior on other queries and datasets.

Interesting note:
When using SPARQLAlgebra.js to convert the algebra object made by GraphQL-LD into sparql code and then back into an algebra object (producing a new but very different algebra object, I realise multiple algebra objects can represent the same query, but perhaps this could help towards debugging), the problem was solved.

Context for reference:

{
        "schema": "http://schema.org/",
        "ex": "http://example.com/rmlio/",
        "type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
        "softwareCategory": "ex:softwareCategory",
        "linkSet": "ex:linkSet",
        "slug": "ex:slug",
        "name": "schema:name",
        "description": "schema:description",
        "tools": "ex:content",
        "abstract": "schema:abstract",
        "links": "ex:linkSet",
        "url": "schema:url"
}
@rubensworks
Copy link
Owner

Are you certain you're using the latest versions of everything? (how are you invoking this code?) Because if calling graphql-to-sparql.js manually works, then I guess it's a versioning issue.

@renevds
Copy link
Author

renevds commented Jul 14, 2021

@rubensworks
It would seem I had linked the wrong repo in my "interesting note", I made a correction, it should make more sense now.
I'm using GraphQl-LD withinWalder.
I will check if versioning is the problem.

@pheyvaer
Copy link

We are using the latest version:

"graphql-ld": "^1.4.0",
"graphql-ld-comunica": "^1.2.1",

@pheyvaer
Copy link

I've made a failing example

JavaScript:

var Client = require("graphql-ld").Client;
const QueryEngineComunica = require('graphql-ld-comunica').QueryEngineComunica;

main();

async function main() {
// Define a JSON-LD context
  const context = {
    "@context":           {
      "type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
      "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
      "owl": "http://www.w3.org/2002/07/owl#",
      "label": "rdfs:label",
      "comment": "rdfs:comment",
      "domain": "rdfs:domain",
      "range": "rdfs:range",
      "DatatypeProperty": "owl:DatatypeProperty"
    }
  };

// Create a GraphQL-LD client based on a client-side Comunica engine over 2 sources
  const comunicaConfig = {
    sources: ["http://localhost:8080/rml.ttl"],
  };
  const client = new Client({context, queryEngine: new QueryEngineComunica(comunicaConfig)});

// Define a query
  const query = `
              {
              id @single
              type (_:DatatypeProperty)
              label @single
              comment @single
              domain @optional
              range @optional
            }`;

// Execute the query
  const {data} = await client.query({query});

  console.log(data);
}

Data:

@prefix cc:			<http://creativecommons.org/ns#> .
@prefix dcterms:		<http://purl.org/dc/terms/> .
@prefix xsd: 			<http://www.w3.org/2001/XMLSchema#> .
@prefix owl: 			<http://www.w3.org/2002/07/owl#> .
@prefix foaf: 			<http://xmlns.com/foaf/0.1/> .
@prefix ql: 			<http://semweb.mmlab.be/ns/ql#> .
@prefix rml: 			<http://semweb.mmlab.be/ns/rml#> .
@prefix rmlt: 			<http://semweb.mmlab.be/ns/rml-target#> .
@prefix rr: 			<http://www.w3.org/ns/r2rml#> .
@prefix rdf: 			<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: 			<http://www.w3.org/2000/01/rdf-schema#> .
@prefix vann: 			<http://purl.org/vocab/vann/> .
@prefix xml: 			<http://www.w3.org/XML/1998/namespace> .
@prefix : 	    		<http://semweb.mmlab.be/ns/rml#> .
@base 		    		<http://semweb.mmlab.be/ns/rml#> .

###  http://semweb.mmlab.be/ns/rml#iterator

rml:iterator rdf:type owl:DatatypeProperty ;
    rdfs:label   "iterator" ;
    rdfs:comment "an expression qualified according to the reference formulation specified for pointing to an extract of the source data. "@en ;
    rdfs:domain  rml:LogicalSource;
    rdfs:range   xsd:string .


###  http://semweb.mmlab.be/ns/rml#reference

rml:reference rdf:type owl:DatatypeProperty ;
    rdfs:label   "reference" ;
    rdfs:comment "A valid expression that selects values from the source data. The reference should confront to the syntax rules/grammar of the specified Reference Formulation. "@en ;
    rdfs:domain  rr:TermMap;
    rdfs:range   xsd:string .


###  http://semweb.mmlab.be/ns/rml#version

rml:version rdf:type owl:DatatypeProperty ;
    rdfs:label   "version" ;
    rdfs:comment "It defines the version of the reference Formulation used. "@en ;
    rdfs:domain  rml:LogicalSource;
    rdfs:range   xsd:string .

###  http://semweb.mmlab.be/ns/rml#source

rml:source rdf:type rdf:Property ;
    rdfs:label   "source" ;
    rdfs:comment "qualified name of the source data."@en ;
    rdfs:domain  rml:LogicalSource .


###  http://mmlab.be/rml#query

rml:query rdf:type owl:DatatypeProperty ;
    rdfs:comment "A valid query."@en ;
    rdfs:domain  rml:LogicalSource .

The owl:DatatypeProperty instances without rdfs:range are not found, while range is optional in the query.

@rubensworks rubensworks added the bug Something isn't working label Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants