@@ -169,14 +169,37 @@ async function createInstanceNodes(from: string): Promise<Array<object>> {
169
169
* @returns SPARQL query result object
170
170
*/
171
171
async function selectTriples ( from : string , fromNamed : string , instances : boolean , virtual : boolean ) : Promise < Array < object > > {
172
+ let idA , idB , idC , idD ;
173
+ const isValidHttpUrl = ( str ) => {
174
+ // https://stackoverflow.com/a/43467144
175
+ let url ;
176
+
177
+ try {
178
+ url = new URL ( str ) ;
179
+ } catch ( _ ) {
180
+ return false ;
181
+ }
182
+ return url . protocol === "http:" || url . protocol === "https:" ;
183
+ } ;
184
+ if ( config . sparql . classId === "a owl:Class" ) {
185
+ idA = config . sparql . classId ;
186
+ idB = config . sparql . classId ;
187
+ idC = config . sparql . classId ;
188
+ idD = config . sparql . classId ;
189
+ } else if ( isValidHttpUrl ( config . sparql . classId ) || / ^ \w + : \w + $ / . test ( config . sparql . classId ) ) {
190
+ idA = config . sparql . classId + " ?x" ;
191
+ idB = config . sparql . classId + " ?y" ;
192
+ idC = idA + 1 ;
193
+ idD = idB + 1 ;
194
+ }
172
195
const sparqlPropertiesTimer = timer ( "sparql-properties" ) ;
173
196
const tripleQuerySimple = `
174
197
select ?c ?p ?d
175
198
${ from }
176
199
{
177
200
{?c ?p ?d.} ${ virtual ? " UNION {?p rdfs:domain ?c; rdfs:range ?d.}" : "" }
178
- {?c a owl:Class .} ${ instances ? " UNION {?c a [a owl:Class]}" : "" }
179
- {?d a owl:Class .} ${ instances ? " UNION {?d a [a owl:Class]}" : "" }
201
+ {?c ${ idA } .} ${ instances ? ` UNION {?c a [${ idC } ]}` : "" }
202
+ {?d ${ idB } .} ${ instances ? ` UNION {?d a [${ idD } }` : "" }
180
203
}` ;
181
204
// the optional part should be a union
182
205
const tripleQuerySnik = `PREFIX sniko: <http://www.snik.eu/ontology/>
0 commit comments