Line 168: |
Line 168: |
| function quickpresets_checktype(qid, prop) { | | function quickpresets_checktype(qid, prop) { |
| var typeqid=prop.qid; | | var typeqid=prop.qid; |
− | mw.notify("qid "+qid+" typeqid "+typeqid);
| |
| // Search in HTML-DOM | | // Search in HTML-DOM |
| + | // 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(value, index) { |
| if(typeof value.attributes.href === "undefined") | | if(typeof value.attributes.href === "undefined") |
| { | | { |
− | mw.notify("exit 1");
| + | return []; |
− | return []; | |
| } | | } |
| else | | else |
| { | | { |
− | mw.notify("exit 2");
| |
| return [value.attributes.href.value.substring(6)]; | | return [value.attributes.href.value.substring(6)]; |
| } | | } |
| }); | | }); |
− | mw.notify(typefromdom) | + | // typefromdom is now a list of Item:Qxxx, possibly empty |
| if ( typefromdom.length === 0) { | | if ( typefromdom.length === 0) { |
− | mw.notify("null typefromdom")
| + | if(typeqid === null) // the null prescription for when there is no "instance of" |
− | if(typeqid === null)
| + | { |
− | {
| + | mw.notify("exit 3") |
− | mw.notify("exit 3")
| + | quickpresets_addinterface(qid, prop); |
− | quickpresets_addinterface(qid, prop);
| + | } |
− | }
| |
| } | | } |
| else { | | else { |
− | mw.notify("exit 4")
| + | mw.notify("exit 4") |
− | if ( typeqid === 0 ) {
| + | if ( typeqid === 0 ) { |
− | mw.notify("exit 5")
| + | // the 0 prescription, applicable to all items which are instance of something |
− | quickpresets_addinterface(qid, prop);
| |
− | }
| |
− | else if ( typefromdom.includes("Item:Q"+typeqid) ) {
| |
− | mw.notify("exit 6")
| |
− | quickpresets_addinterface(qid, prop);
| |
− | }
| |
− | else {
| |
− | mw.notify("exit 7")
| |
− | // 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' };
| |
− | fetch( fullUrl, { headers } ).then( body => body.json() ).then( json => {
| |
− | if ( json.boolean )
| |
| quickpresets_addinterface(qid, prop); | | 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', |
| + | 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' }; |
| + | fetch( fullUrl, { headers } ).then( body => body.json() ).then( json => { |
| + | if ( json.boolean ) |
| + | quickpresets_addinterface(qid, prop); |
| + | } ); |
| + | } |
| } | | } |
| } | | } |