More examples

Here are some examples of PyQL program.

Example 1

  • Question

Is the ship with the largest payload among Cristóbal Colón, HMS Good Hope, and SMS Scharnhorst the slowest one?

  • Program

a=PyQL()
a.add_assignment(['Q1140473','Q1032039','Q533999'],'x2')
a.add_quantity('x2','P2109','x0')
a.add_max('x0')
b=PyQL()
b.add_assignment(['Q1140473','Q1032039','Q533999'],'x3')
b.add_quantity('x3','P2052','x1')
b.add_min('x1')
c=PyQL()
c.add_compare('x0','=','x1')
c.add_sub_query(a,b)
print(c.sparql)
  • sparql generated by the program above

SELECT ?x0 {
	{
		SELECT DISTINCT * {
			Values ?x1 {wd:Q1140473 wd:Q1032039 wd:Q533999}
			?x1 p:P2109 ?x2.
			?x2 psv:P2109 ?x3.
			?x3 wikibase:quantityAmount ?x1_playload.
		}
		ORDER BY DESC(?x1_playload)
		LIMIT 1
	}
	{
		SELECT DISTINCT * {
			Values ?x5 {wd:Q1140473 wd:Q1032039 wd:Q533999}
			?x5 p:P2052 ?x6.
			?x6 psv:P2052 ?x7.
			?x7 wikibase:quantityAmount ?x5_speed.
		}
		ORDER BY (?x5_speed)
		LIMIT 1
	}
	BIND( (IF(?x1_playload = ?x5_speed, "TRUE", "FALSE")) AS ?x0 )
}

Example 2

  • Question

How many times does the difference in the longest span of Dardanelles Bridge and Morandi Bridge of that of Millau Viaduct?

  • Program

  • sparql generated by the program above

Last updated