How do I create new linked data in my Solid pod

I am creating an Angular application to save linked data in a pod. I am however new to linked data and using ontologies and am trying to find the best way to create for instance a survey with questions and answers following this ontology: The Survey Ontology and store it in a Solid pod. But how do I do this via the solid libraries using SolidDataset and Things? Do I need to manually set all these fields and urls or is there another way? How do I link then an Answer to a Question?

  const question= buildThing(createThing({ name: "question 1"))
  .addUrl(RDF.type, "https://w3id.org/survey-ontology#ClosedQuestion")
  .build();   


  const newAnswer = buildThing(createThing({ name: "Answer 1"))
  .addUrl(RDF.type, "https://w3id.org/survey-ontology#surveyAnswer")
  .build();   

Are there any code examples how similar things like this can be done with Typescript/javascript?

Thanks!

Could something in this example help you ?

Thanks that helped! I got it working!!!

const question2= buildThing(createThing({ name: "question2"}))
    .addStringNoLocale(SCHEMA_INRUPT.text, "question 2?")
    .addUrl(RDF.type, "https://w3id.org/survey-ontology#ClosedQuestion")
    .build();  

    const question1= buildThing(createThing({ name: "question1"}))
    .addStringNoLocale(SCHEMA_INRUPT.text, "question1?")
    .addUrl(RDF.type, "https://w3id.org/survey-ontology#ClosedQuestion")
    .addUrl("https://w3id.org/survey-ontology#leadsTo", question2)
    .build();  

1 Like

:smiley::+1: great welcome, don’t hesitate to ask

There is still something wrong I see.
If I store my answers under a new dataset and I want to link the answers to the questions like follows:

 let myDataset = createSolidDataset();
              saveSolidDatasetAt(this.userService.getRootName() + "survey", myDataset, {
                fetch: this.session.fetch
              }).then((result)=>this.saveSurvey(result));
...
// saveSurvey function: 
const question1= buildThing(createThing({ name: "question1"}))
    .addStringNoLocale(SCHEMA_INRUPT.text, "question 1?")
    .addUrl(RDF.type, "https://w3id.org/survey-ontology#ClosedQuestion")
    .build();  

dataset1= setThing(result, question1);
this.question1 = question1;

...
 saveSolidDatasetAt(this.userService.getRootName() + "survey", result, {
    fetch: this.session.fetch
  }).then((result) => {
    ...
    let answerDAtaset= createSolidDataset();
          saveSolidDatasetAt(this.userService.getRootName() + "answer", 
      answerDAtaset, {
            fetch: this.session.fetch
          }).then((result)=>this.saveAnswer(result));
})

...
saveAnswer(result:any ): any {


  const answer= buildThing(createThing({ name: "answer"}))
    .addStringNoLocale(SCHEMA_INRUPT.text, this.form.get("answer")?.value)
    .addUrl(RDF.type, "https://w3id.org/survey-ontology#ClosedQuestion")
    .addUrl("https://w3id.org/survey-ontology#completesQuestion", this.question1!)
    .build(); 
   
    result = setThing(result, answer);

    saveSolidDatasetAt(this.userService.getRootName() + "answer", result, {
      fetch: this.session.fetch
    }).then((result) => {
...
}
  
  

then he is not linking correctly to the question. When I check my pod, it should be:

https:// frederikbyl.solidcommunity.net/private/survey#question1
and it’s:
https:// frederikbyl.solidcommunity.net/private/answers#question1

So it is using the wrong base url for question1 thing… .

Aha, it’s probably because of the following:

/**
 * A [[Thing]] whose full Subject URL will be determined when it is persisted.
 */
export declare type ThingLocal = Thing & {
    url: LocalNodeIri;
};
/**
 * Represents the BlankNode that will be initialised to a NamedNode when persisted.
 *
 * This is a Blank Node with a `name` property attached, which will be used to construct this
 * Node's full URL once it is persisted, where it will transform into a Named Node.
 *
 * @hidden Utility type; library users should not need to interact with LocalNodes directly.
 */
export declare type LocalNode = NamedNode<LocalNodeIri>;

We can’t see your files in private folder

As I understand, you want to create 2 things in the same dataset or on two dataset, quite similar to Create two Things in a SolidDataset with @inrupt/solid-client - #2 by Vincent

1 Like

Yes indeed, but they are in seperate SolidDatasets. I expected the url of the Thing to be absolute, but it’s relative, so it only contains the part behind the dataset url. So I fixed it with concatenating the solidDataset urls with the Thing relative urls… . not ideal…

The URL of a Thing is relative until it is saved somewhere - after all, before saving it somewhere, it cannot be known yet what the absolute URL will be.

(Keep in mind that the data is immutable, i.e. if you get a Thing from a SolidDataset, its URL won’t change even if you later save that SolidDataset. You’ll have to pull the updated Thing from the SolidDataset that represents stored data to get the full URL.)

1 Like