Skip to content

Instantly share code, notes, and snippets.

@situx
Created February 27, 2022 23:10
Show Gist options
  • Save situx/be77efc53d532269b6f86167d465ac07 to your computer and use it in GitHub Desktop.
Save situx/be77efc53d532269b6f86167d465ac07 to your computer and use it in GitHub Desktop.
Wikidata Recogito Lexeme Test
class WikidataLexeme {
constructor(opt_config) {
this.name = opt_config?.name || 'WikidataLexeme';
this.config = opt_config;
}
query(query, globalConfig) {
return this.queryFiltered(query, globalConfig)
}
queryFiltered(query, globalConfig) {
const lang = globalConfig.language || 'en';
const limit = globalConfig.limit || 20;
const sparql = `
SELECT DISTINCT ?l ?lf ?lemma ?senseval ?senselabel ?lfgram ?gflabel WHERE {
?l rdf:type ontolex:LexicalEntry ;
dct:language wd:Q1860 ;
wikibase:lexicalForm ?lf .
?lf wikibase:grammaticalFeature ?lfgram .
?l ontolex:sense ?sense . ?sense wdt:P5137 ?senseval . OPTIONAL { ?senseval rdfs:label ?senselabel . }
?lfgram rdfs:label ?gflabel .
?lf ontolex:representation "${query}"@${lang} .
FILTER((LANG(?gflabel))= "${lang}")
FILTER((LANG(?senselabel))= "${lang}")
}
LIMIT ${limit}
`;
const url = wd.sparqlQuery(sparql);
return fetch(url)
.then(response => response.json())
.then(data => data.results.bindings.map(result => {
return {
uri: result.lf.value,
label: result.lemma.value+" ("+result.gflabel.value+") ["+result.senselabel.value+"]",
description: result.senselabel.value
};
}));
}
doFetch(url) {
}
}
WikidataLexeme.matches = tag =>
tag.uri.match(/^https?:\/\/www.wikidata.org\/entity\/L/g);
WikidataLexeme.format = tag =>
tag.uri.substring(tag.uri.indexOf('entity/L') + 7);
var semantictagsconfig={
dataSources: [
'Wikidata',
'VIAF',
{ source: new WikidataLexeme(), name: 'WikidataLexeme' }
],
availableLanguages: [
'en', 'de', 'fa'
],
limit: 10
}
r = Recogito.init({
content: document.getElementById('transliteration'), // ID or DOM element
readOnly: true,
widgets: [
'COMMENT',
{
widget: 'TAG',
vocabulary: contentVocabulary.concat(linguisticVocabulary)
},
recogito.SemanticTags(semantictagsconfig)
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment