• No results found

Rules for Conditional Queries

8.8 Query Generator

8.8.1 Rules for Conditional Queries

8.8.1.1 Negation

The Query Generator handles negation in two ways as given below. A. Using Logical NOT (!)

To apply negation to an instance or Named Entity, the Query Generator uses logical not (!) operator with a regular expression in FILTER clause. Below is an example of a query (using logical not (!)) that finds all persons whose family name is not ‘hardy’.

S E L E C T * W H E R E {

{? P e r s o n a < h t t p :// x m l n s . com / f o a f / 0 . 1 / Person >}

{? P e r s o n < h t t p :// x m l n s . com / f o a f / 0 . 1 / g i v e n N a m e > ? g i v e n _ n a m e } {? P e r s o n < h t t p :// x m l n s . com / f o a f / 0 . 1 / f a m i l y N a m e > ? f a m i l y _ n a m e }

8. GENERATING SPARQL QUERIES

F I L T E R (! R E G E X ( str (? f a m i l y _ n a m e ) ," h a r d y " ," i ") ) }

B. Using NOT EXISTS

To apply negation to a class or property concept, the Query Generator utilises NOT EXISTS keyword in FILTER clause. Below is an example of a query (using NOT EXISTS) that finds all the persons who are not dead.

S E L E C T * W H E R E { {? P e r s o n a < h t t p :// x m l n s . com / f o a f / 0 . 1 / Person >} {? P e r s o n < h t t p :// x m l n s . com / f o a f / 0 . 1 / g i v e n N a m e > ? g i v e n _ n a m e } {? P e r s o n < h t t p :// x m l n s . com / f o a f / 0 . 1 / f a m i l y N a m e > ? f a m i l y _ n a m e } F I L T E R ( NOT E X I S T S {? P e r s o n < h t t p :// d b p e d i a . org / o n t o l o g y / d e a t h D a t e > ? d a t e }) } 8.8.1.2 Conjunction

Conjunction in this context, is used to build a relation between two syntactic pairs con- nected by coordinating conjunctions such as ‘and’ or ‘or’ e.g. “find person whose name is john or jack”. The Query Generator receives syntactic pairs with related conjunctions and processes them using logical OR (||) and logical AND (&&) operators in SPARQL. For the given query, the Query Generator receives syntactic pairs with related conjunctions [e.g. or( (name, john), (name, jack))] and produces the following SPARQL query.

S E L E C T * W H E R E { {? P e r s o n a < h t t p :// x m l n s . com / f o a f / 0 . 1 / Person >} {? P e r s o n < h t t p :// x m l n s . com / f o a f / 0 . 1 / name > ? n a m e } F I L T E R ( R E G E X (? name , " j a c k " , " i ") || R E G E X (? name , " j o h n " , " i ") ) } 8.8.1.3 Numeric Quantifiers

The numeric quantifiers are the numeric quantities specified for a concept or noun. If numeric quantifiers are attached to a class or property, the Query Generator attempts to solve it using the LIMIT keyword defined in SPARQL e.g. for a query “list 50 persons born in 1972” the Query Generator will generate following SPARQL query.

8. GENERATING SPARQL QUERIES {? P e r s o n a < h t t p :// x m l n s . com / f o a f / 0 . 1 / Person >} {? P e r s o n < h t t p :// x m l n s . com / f o a f / 0 . 1 / name > ? n a m e } {? P e r s o n < h t t p :// d b p e d i a . org / o n t o l o g y / b i r t h D a t e > ? d a t e } F I L T E R (? d a t e = " 1 9 7 2 " ^ ^ < h t t p :// www . w3 . org / 2 0 0 1 / X M L S c h e m a # gYear >) } L I M I T 50

If the numeric quantifier is attached to an instance variable, the Query Generator will solve it using comparison operators i.e. equal to (=), greater than (>), greater than and equal to (>=), less than (<) and less than and equal to (<=). For example for a query “list upto 50 persons whose age is above 50”, the Query Generator will generate following query.

S E L E C T * W H E R E {

{? P e r s o n a < h t t p :// x m l n s . com / f o a f / 0 . 1 / Person >} {? P e r s o n < h t t p :// x m l n s . com / f o a f / 0 . 1 / name > ? n a m e } {? P e r s o n < h t t p :// d b p e d i a . org / o n t o l o g y / age > ? age } F I L T E R (? age > 50)

} L I M I T 50

Related documents