Skip to content

About

Translates RDF into human languages. Useful for making data understandable for AI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

header

RDF to text

Translates RDF into human languages. Supported file formats:

  • Turtle
  • TriG
  • N-Triples
  • N-Quads

Available ontology translations

See the list here. Contribute prose annotations.

How to use

The translation produced for a dataset depends on:

  1. the dictionaries used for translating ontologies to human languages, and
  2. the user's language preferences.

Note that the translated dataset can also contain translations.

Here are the predicates that define a translation for an IRI or blank node:

  • For ontologies: qrmm:prose, with rdfs:label as the lower-priority fallback. Blank nodes are not translated.
  • In the translated (non-ontology) datasets: qrmm:prose, foaf:name, schema:name, schema:givenName, with rdfs:label as the lower-priority fallback.
import { 
  Translator, OntologyDictionary, parse, langTag, LanguagePreferences,
} from "https://cdn.jsdelivr.net/gh/doga/rdf-to-text@1.1.1/mod.mjs";

await run();

async function run(){
  const
  dataset = await parse(`
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    PREFIX qrmm: <https://vocab.qworum.net/qrmm.ttl#>
    PREFIX qrmd: <https://vocab.qworum.net/qrmd.ttl#>
    PREFIX :     <http://site.example/>

    :jonka a foaf:Person ;
      foaf:name 'Jon Ka'.

    :jimdo a foaf:Person ;
      foaf:name 'Jim Do'.

    :canan a foaf:Person ;
      foaf:name 'Can An'.

    << :jimdo foaf:weblog 'https://weblog.jimdo.me'^^qrmd:anyIRI >>
      :acc :jonka .

    << :jimdo foaf:knows :canan >>
      :says :jonka .
    
    :acc  qrmm:prose 'is according to'@en.
    :says qrmm:prose 'is what :object says'@en.
  `),
  dictionaries = [
    await buildFoafDictionary(),
    await buildRdfDictionary()
  ],
  langPrefs = new LanguagePreferences(
    ['en', 'fr-CA', 'de', 'tr-TR'].map(e => langTag`${e}`)
  ),

  //▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
  translator  = new Translator(langPrefs),
  translation = translator.translate(dataset, dictionaries);
  //▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲

  console.info(translation.filter(str => str !== null).join('\n'));
}

async function buildRdfDictionary() {
  const 
  dataset = await parse(`
    PREFIX qrmm: <https://vocab.qworum.net/qrmm.ttl#>
    PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

    rdf:type   qrmm:prose 'is'@en.
    rdfs:label qrmm:prose 'is'@en.
  `),
  dictionary = new OntologyDictionary();
  dictionary.addDataset(dataset);
  return dictionary;
}

async function buildFoafDictionary() {
  const 
  dataset = await parse(`
    PREFIX qrmm: <https://vocab.qworum.net/qrmm.ttl#>
    PREFIX foaf: <http://xmlns.com/foaf/0.1/>

    foaf:Person qrmm:prose 'a person'@en.
    foaf:name   qrmm:prose 'is named'@en, 'est nommé'@fr, 'hat den Namen'@de.
    foaf:weblog qrmm:prose 'has the weblog'@en.
    foaf:knows  qrmm:prose 'knows'@en.
  `),
  dictionary = new OntologyDictionary();
  dictionary.addDataset(dataset);
  return dictionary;
}

The output:

Jon Ka is a person.
Jim Do is a person.
Can An is a person.
Jim Do has the weblog https://weblog.jimdo.me; this is according to Jon Ka.
Jim Do knows Can An; this is what Jon Ka says.

∎

About

Translates RDF into human languages. Useful for making data understandable for AI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages