forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'service_question_generator' into webapp_interface
- Loading branch information
Showing
3 changed files
with
167 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
questionsservice/questiongeneratorservice/wikidataExtractor/wikidataConnexion.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
async function consulta(query) { | ||
const apiUrl = `https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}&format=json`; | ||
console.log(query) | ||
const respuesta = await fetch(apiUrl, { | ||
headers: { | ||
'User-Agent': 'QuestionCrawler/1.0', | ||
'Accept': 'application/json' | ||
} | ||
}); | ||
// console.log(apiUrl) | ||
// console.log(respuesta) | ||
if (!respuesta.ok) { | ||
console.error('Error al realizar la consulta a Wikidata:', respuesta.statusText); | ||
return; | ||
} | ||
|
||
const datos = await respuesta.json(); | ||
|
||
const resultados = []; | ||
|
||
for (const resultado of datos.results.bindings) { | ||
const resultadoFormateado = {}; | ||
for (const clave in resultado) { | ||
resultadoFormateado[clave] = resultado[clave].value; | ||
} | ||
resultados.push(resultadoFormateado); | ||
} | ||
|
||
return resultados; | ||
} | ||
|
||
module.exports = {consulta} |
28 changes: 28 additions & 0 deletions
28
questionsservice/questiongeneratorservice/wikidataExtractor/wikidataQueries.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const wikidata = require("./wikidataConnexion"); | ||
|
||
class WikiQueries { | ||
|
||
static async obtenerPaisYCapital() { | ||
const query = ` | ||
SELECT ?countryLabel ?capitalLabel WHERE { | ||
?country wdt:P31 wd:Q6256. | ||
?country wdt:P36 ?capital. | ||
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". } | ||
} | ||
`; | ||
|
||
const results = await wikidata.consulta(query); | ||
// console.log(results) | ||
return results; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
module.exports = WikiQueries |