Line 173: |
Line 173: |
| */ | | */ |
| function quickpresets_checktype(qid, prop) { | | function quickpresets_checktype(qid, prop) { |
− | var typeqid=prop.qid;
| + | var typeqid = prop.qid; |
− | // Search in HTML-DOM
| + | // Search in HTML-DOM |
− | // for each "instance of" value, run this function
| + | // for each "instance of" value, run this function |
− | var typefromdom=$.map($('#P3').find(".wikibase-snakview-value a"), function(value, index) {
| + | var typefromdom = $.map($("#P3").find(".wikibase-snakview-value a"), function( |
− | if(typeof value.attributes.href === "undefined")
| + | value, |
− | {
| + | index |
− | return [];
| + | ) { |
− | }
| + | if (typeof value.attributes.href === "undefined") { |
− | else
| + | return []; |
− | {
| + | } else { |
− | return [value.attributes.href.value.substring(6)];
| + | return [value.attributes.href.value.substring(6)]; |
− | }
| |
− | });
| |
− | // typefromdom is now a list of Item:Qxxx, possibly empty
| |
− | if ( typefromdom.length === 0) {
| |
− | if(typeqid === null) // the null prescription for when there is no "instance of"
| |
− | {
| |
− | quickpresets_addinterface(qid, prop);
| |
− | }
| |
| } | | } |
− | else {
| + | }); |
− | if ( typeqid === 0 ) {
| + | // typefromdom is now a list of Item:Qxxx, possibly empty |
− | // the 0 prescription, applicable to all items which are instance of something
| + | if (typefromdom.length === 0) { |
− | quickpresets_addinterface(qid, prop);
| + | if (typeqid === null) { |
− | }
| + | // the null prescription for when there is no "instance of" |
− | else if ( typefromdom.includes("Item:Q"+typeqid) ) {
| + | quickpresets_addinterface(qid, prop); |
− | // direct relevance
| |
− | quickpresets_addinterface(qid, prop);
| |
− | }
| |
− | else {
| |
− | // indirect relevance, through subclassing
| |
− | // Now check via sparql (much slower but includes subtypes)
| |
− | const endpointUrl = 'https://query.personaldata.io/proxy/wdqs/bigdata/namespace/wdq/sparql',
| |
− | sparqlQuery = 'Ask { pdio:Q' + qid + ' pdiot:P3/pdiot:P4* pdio:Q' + typeqid + '. hint:Prior hint:gearing "forwards" }',
| |
− | fullUrl = endpointUrl + '?query=' + encodeURIComponent( sparqlQuery ),
| |
− | headers = { 'Accept': 'application/sparql-results+json' };
| |
− | debug("qid: "+ qid + "\ntypeqid: " + typeqid + "\n" + fullUrl + "\n" + sparqlQuery);
| |
− | fetch( fullUrl, { headers: { 'Accept': 'application/sparql-results+json' }, } )
| |
− | .then( body => { body.json() } )
| |
− | .then( json => { if ( json.boolean ) quickpresets_addinterface(qid, prop); } );
| |
− | }
| |
| } | | } |
| + | } else { |
| + | if (typeqid === 0) { |
| + | // the 0 prescription, applicable to all items which are instance of something |
| + | quickpresets_addinterface(qid, prop); |
| + | } else if (typefromdom.includes("Item:Q" + typeqid)) { |
| + | // direct relevance |
| + | quickpresets_addinterface(qid, prop); |
| + | } else { |
| + | // indirect relevance, through subclassing |
| + | // Now check via sparql (much slower but includes subtypes) |
| + | const endpointUrl = "https://query.personaldata.io/proxy/wdqs/bigdata/namespace/wdq/sparql"; |
| + | const sparqlQuery = "Ask { pdio:Q" + qid + " pdiot:P3/pdiot:P4* pdio:Q" + typeqid + '. hint:Prior hint:gearing "forwards" }'; |
| + | const fullUrl = endpointUrl + "?query=" + encodeURIComponent(sparqlQuery); |
| + | const myHeaders = { Accept: "application/sparql-results+json" }; |
| + | debug("qid: " + qid + "\ntypeqid: " + typeqid + "\n" + fullUrl + "\n" + sparqlQuery ); |
| + | fetch(fullUrl, { headers: myHeaders }) |
| + | .then(function(body) {body.json();}) |
| + | .then(function(json) {if (json.boolean) {quickpresets_addinterface(qid, prop);}}); |
| + | } |
| + | } |
| } | | } |
| | | |