diff --git a/questions/services/generate-questions-service.js b/questions/services/generate-questions-service.js index fe467689..438190c8 100644 --- a/questions/services/generate-questions-service.js +++ b/questions/services/generate-questions-service.js @@ -24,7 +24,7 @@ async function generateQuestions(n, language, questionCategory) { // get data for selected entity let pos = Math.floor(Math.random() * entity.properties.length); - + //use only property of that required category if(questionCategory) { const filteredProperties = []; @@ -33,6 +33,7 @@ async function generateQuestions(n, language, questionCategory) { filteredProperties.push(property); } }); + const randomPos = Math.floor(Math.random() * filteredProperties.length); const propertyJson = filteredProperties[randomPos]; pos = entity.properties.findIndex(prop => prop === propertyJson); diff --git a/questions/services/wikidata-service.js b/questions/services/wikidata-service.js index 9684d293..f9f76bdb 100644 --- a/questions/services/wikidata-service.js +++ b/questions/services/wikidata-service.js @@ -1,6 +1,7 @@ const axios = require('axios'); async function getRandomEntity(entity, pos, language) { + const property = entity.properties[pos].property; const filt = entity.properties[pos].filter; var filter = ''; @@ -22,13 +23,12 @@ async function getRandomEntity(entity, pos, language) { `; // it is better to use the FILTER rather than SERVICE //SERVICE wikibase:label { bd:serviceParam wikibase:language "es". } - + const urlApiWikidata = 'https://query.wikidata.org/sparql'; const headers = { 'User-Agent': 'QuestionGeneration/1.0', 'Accept': 'application/json', }; - try { response = await axios.get(urlApiWikidata, { params: { @@ -37,14 +37,16 @@ async function getRandomEntity(entity, pos, language) { }, headers: headers, }); - + + const data = await response.data const entities = data.results.bindings; - + if (entities.length > 0) { const randomEntity = entities[Math.floor(Math.random() * entities.length)]; const entityName = randomEntity.entityLabel.value; const property = randomEntity.property.value; + console.log("ENTITY, PROPERTY: ",entityName, property); return [entityName, property]; } else { return null; @@ -95,6 +97,7 @@ async function getProperties(property, language, filt) { for(var i = 0; i < 3 ; i++) { properties[i] = list[Math.floor(Math.random() * list.length)].property.value; } + console.log("PROPERTIES: ",properties); return properties; } return null; diff --git a/questions/utils/question.json b/questions/utils/question.json index 9b48cb34..32aafbe5 100644 --- a/questions/utils/question.json +++ b/questions/utils/question.json @@ -91,7 +91,7 @@ "lang": "en", "question": "What country is x river in" }], - "category": ["Geography"] + "category": ["Geography", "River"] } ] }, @@ -112,18 +112,6 @@ }], "category": ["Art"] }, - { - "property": "P571", - "template": [{ - "lang": "es", - "question": "Cual es el año de creacion de x" - }, - { - "lang": "en", - "question": "What is the year of creation of x" - }], - "category": ["Art"] - }, { "property": "P136", "template": @@ -155,19 +143,6 @@ "question": "Who is the inventor of x" }], "category": ["Science"] - }, - { - "property": "P575", - "template": - [{ - "lang": "es", - "question": "En que año se inventó x" - }, - { - "lang": "en", - "question": "What was the year of invention of x" - }], - "category": ["Science"] } ] }, @@ -180,19 +155,20 @@ "template": [{ "lang": "es", - "question": "Cual es la altitud mxima del x" + "question": "Cual es la altitud de la montaña x" }, { "lang": "en", "question": "What is the maximum altitude of x" }], - "category": ["Geography"] + "filter": ">4000", + "category": ["Geography", "Mountains"] } ] }, { "name": "book", - "instance": "Q571", + "instance": "Q7725634", "properties": [ { "property": "P50", @@ -207,18 +183,6 @@ }], "category": ["Entertainment"] }, - { - "property": "P577", - "template": [{ - "lang": "es", - "question": "Cual es el año de publicacion de x" - }, - { - "lang": "en", - "question": "What is the year of publication of x" - }], - "category": ["Entertainment"] - }, { "property": "P136", "template": @@ -235,125 +199,7 @@ ] }, { - "name": "vehicle", - "instance": "Q42889", - "properties": [ - { - "property": "P176", - "template": - [{ - "lang": "es", - "question": "Quien es el fabricante de x" - }, - { - "lang": "en", - "question": "Who is the manufacturer of x" - }], - "category": ["Cars"] - }, - { - "property": "P3032", - "template": [{ - "lang": "es", - "question": "Cuál es la velocidad máxima de x" - }, - { - "lang": "en", - "question": "What is the maximum speed of x" - }], - "category": ["Cars"] - }, - { - "property": "P571", - "template": - [{ - "lang": "es", - "question": "En qué año fue introducido x al mercado" - }, - { - "lang": "en", - "question": "In what year was x introduced to the market" - }], - "category": ["Cars"] - } - ] - }, - { - "name": "dish", - "instance": "Q746549", - "properties": [ - { - "property": "P527", - "template": - [{ - "lang": "es", - "question": "Cuál es el ingrediente principal de x" - }, - { - "lang": "en", - "question": "What is the main ingredient of x" - }], - "category": ["Food"] - }, - { - "property": "P495", - "template": [{ - "lang": "es", - "question": "De qué región es originario x" - }, - { - "lang": "en", - "question": "What region is x originally from?" - }], - "category": ["Food"] - } - ] - }, - { - "name": "building", - "instance": "Q41176", - "properties": [ - { - "property": "P84", - "template": - [{ - "lang": "es", - "question": "Quién fue el arquitecto de x" - }, - { - "lang": "en", - "question": "Who was the architect of x" - }], - "category": ["Art"] - }, - { - "property": "P571", - "template": [{ - "lang": "es", - "question": "En qué año se completó x" - }, - { - "lang": "en", - "question": "In what year was it completed x" - }], - "category": ["Art"] - }, - { - "property": "P149", - "template": [{ - "lang": "es", - "question": "Cuál es el estilo arquitectónico de x" - }, - { - "lang": "en", - "question": "What is the architectural style of x" - }], - "category": ["Art"] - } - ] - }, - { - "name": "television series", + "name": "television series", "instance": "Q5398426", "properties": [ { @@ -379,41 +225,11 @@ "lang": "en", "question": "How many seasons does the series x have?" }], + "filter": ">0", "category": ["Entertainment"] } ] }, - { - "name": "software", - "instance": "Q7397", - "properties": [ - { - "property": "P178", - "template": - [{ - "lang": "es", - "question": "Quién desarrolló el software x" - }, - { - "lang": "en", - "question": "Who developed the software x" - }], - "category": ["Technology"] - }, - { - "property": "P277", - "template": [{ - "lang": "es", - "question": "En qué lenguaje de programación está escrito x" - }, - { - "lang": "en", - "question": "What programming language is x written in?" - }], - "category": ["Technology"] - } - ] - }, { "name": "athlete", "instance": "Q2066131", @@ -462,18 +278,6 @@ }], "category": ["Games"] }, - { - "property": "P577", - "template": [{ - "lang": "es", - "question": "En qué año fue lanzado el videojuego x" - }, - { - "lang": "en", - "question": "In what year was the video game x released?" - }], - "category": ["Games"] - }, { "property": "P400", "template": [{ @@ -488,37 +292,6 @@ } ] }, - { - "name": "jewelry", - "instance": "Q161439", - "properties": [ - { - "property": "P287", - "template": - [{ - "lang": "es", - "question": "Quién es el diseñador de la marca x" - }, - { - "lang": "en", - "question": "Who is the designer of the brand x" - }], - "category": ["Fashion"] - }, - { - "property": "P571", - "template": [{ - "lang": "es", - "question": "Cuándo fue fundada la casa de moda x" - }, - { - "lang": "en", - "question": "When was the fashion house founded x" - }], - "category": ["Fashion"] - } - ] - }, { "name": "taxon", "instance": "Q16521", @@ -549,24 +322,5 @@ "category": ["Animals"] } ] - }, - { - "name": "brands", - "instance": "Q431289", - "properties": [ - { - "property": "P571", - "template": - [{ - "lang": "es", - "question": "Cuándo fue fundada la marca x" - }, - { - "lang": "en", - "question": "When was the brand x founded?" - }], - "category": ["Brands"] - } - ] } ] \ No newline at end of file