|
1 | 1 | ---
|
2 |
| -layout: standard |
| 2 | +layout: mdcontent |
3 | 3 | title: Query examples
|
4 | 4 | ---
|
5 | 5 |
|
6 | 6 |
|
7 |
| -### Get *boolean* returning methods with an *int* parameter |
| 7 | +### Select recursive methods |
8 | 8 |
|
9 |
| - SELECT ?method WHERE { |
10 |
| - ?method a woc:Method . |
11 |
| - ?method woc:returns woc:boolean . |
12 |
| - ?method woc:has_parameter ?par . |
13 |
| - ?par woc:parameter_position 0 . |
14 |
| - ?par woc:type woc:int . |
| 9 | + SELECT ?method |
| 10 | + WHERE { |
| 11 | + ?method a woc:Method ; |
| 12 | + woc:references+ ?method . |
| 13 | + } |
| 14 | + LIMIT 20 |
| 15 | + |
| 16 | + |
| 17 | +### Get the most referenced classes |
| 18 | + |
| 19 | + SELECT ?class (COUNT(DISTINCT ?anotherClass) as ?count) |
| 20 | + WHERE { |
| 21 | + ?class a woc:Class . |
| 22 | + ?method a woc:Method ; |
| 23 | + woc:isDeclaredBy ?anotherClass ; |
| 24 | + woc:references ?class . |
| 25 | + FILTER (?class != ?anotherClass) |
| 26 | + } |
| 27 | + GROUP BY ?class |
| 28 | + ORDER BY DESC(?count) |
| 29 | + LIMIT 3 |
| 30 | + |
| 31 | +### Sort classes by the number of subclasses |
| 32 | + |
| 33 | + SELECT ?superClass (COUNT(DISTINCT ?class) as ?count) |
| 34 | + WHERE { |
| 35 | + ?class a woc:Class; |
| 36 | + woc:extends* ?superClass . |
| 37 | + } |
| 38 | + GROUP BY ?superClass |
| 39 | + ORDER BY DESC(?count) |
| 40 | + LIMIT 3 |
| 41 | + |
| 42 | + |
| 43 | +### Singletons |
| 44 | + |
| 45 | + SELECT DISTINCT ?class |
| 46 | + WHERE { |
| 47 | + ?class woc:hasConstructor ?constructor ; |
| 48 | + woc:hasField ?field ; |
| 49 | + woc:hasMethod ?method . |
| 50 | + ?constructor woc:hasModifier woc:Private . |
| 51 | + ?field woc:hasModifier woc:Static , woc:Private ; |
| 52 | + woc:hasType ?class . |
| 53 | + ?method woc:returns ?field ; |
| 54 | + woc:hasModifier woc:Static , woc:Public . |
| 55 | + } |
15 | 56 |
|
16 |
| - filter not exists { |
17 |
| - ?method woc:has_parameter ?par1 . |
18 |
| - ?par1 woc:parameter_position 1 |
19 |
| - } |
| 57 | + |
| 58 | +### Builder |
| 59 | + |
| 60 | + SELECT DISTINCT ?abstractBuilder ?concreteBuilder ?product |
| 61 | + WHERE { |
| 62 | + ?abstractBuilder a woc:Class; |
| 63 | + woc:hasModifier woc:Abstract ; |
| 64 | + woc:hasField ?field ; |
| 65 | + woc:hasMethod ?abstractBuildMethod ; |
| 66 | + woc:hasMethod ?getter . |
| 67 | + ?product a woc:Class . |
| 68 | + ?field woc:hasType ?product . |
| 69 | + ?getter woc:returns ?field . |
| 70 | + ?abstractBuildMethod woc:hasModifier woc:Abstract . |
| 71 | + ?concreteBuilder woc:extends ?abstractBuilder ; |
| 72 | + woc:hasMethod ?concreteBuildMethod . |
| 73 | + ?concreteBuildMethod woc:overrides ?abstractBuildMethod . |
| 74 | + ?concreteBuildMethod woc:references ?field . |
| 75 | + FILTER NOT EXISTS { |
| 76 | + ?getter woc:hasParameter ?parameter |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + |
| 81 | +### Factories |
| 82 | + |
| 83 | + SELECT DISTINCT ?factory |
| 84 | + WHERE { |
| 85 | + ?abstractClass a woc:Class ; |
| 86 | + woc:hasModifier woc:Abstract . |
| 87 | + ?factory a woc:Class; |
| 88 | + woc:hasMethod ?method . |
| 89 | + ?method woc:hasReturnType/woc:extends* ?abstractClass . |
| 90 | + FILTER NOT EXISTS { |
| 91 | + ?factory woc:hasMethod ?anotherMethod . |
| 92 | + ?anotherMethod woc:hasReturnType ?type ; |
| 93 | + woc:hasModifier woc:Public . |
| 94 | + FILTER NOT EXISTS { |
| 95 | + ?type woc:extends* ?abstractClass . |
| 96 | + } |
| 97 | + } |
20 | 98 | }
|
| 99 | + LIMIT 20 |
21 | 100 |
|
22 | 101 |
|
23 |
| -### Get *lambdas* implementing an *interface* |
| 102 | +### Select all resources associated with Public-key cryptography and, in particular, with RSA |
24 | 103 |
|
| 104 | + SELECT ?r |
| 105 | + WHERE { |
| 106 | + ?r dul:associatedWith |
| 107 | + dbr:Public-key_cryptography , |
| 108 | + dbr:RSA_\(cryptosystem\) . |
| 109 | + } |
| 110 | + |
| 111 | + |
| 112 | +### Select methods to manipulate Zip files |
25 | 113 |
|
26 |
| - SELECT ?lambda WHERE { |
27 |
| - ?lambda woc:functional_implements ?i |
| 114 | + SELECT ?method |
| 115 | + WHERE { |
| 116 | + ?method a woc:Method ; |
| 117 | + dul:associatedWith dbr:Zip_\(file_format\) , dbr:Input\/output |
28 | 118 | }
|
29 | 119 |
|
30 | 120 |
|
31 |
| -### Get methods' usage cases |
| 121 | +### Select methods to read an image at a specified URL, along with the return type |
| 122 | + |
| 123 | + SELECT ?method ?type |
| 124 | + WHERE { |
| 125 | + ?method a woc:Method; |
| 126 | + woc:hasParameter ?parameter ; |
| 127 | + woc:hasReturnType ?type . |
| 128 | + ?parameter dul:associatedWith dbr:Uniform_Resource_Locator, dbr:Image . |
| 129 | + } |
| 130 | + |
32 | 131 |
|
| 132 | +### Select methods to compute the cube root of a parameter of type double |
33 | 133 |
|
34 |
| - SELECT ?invoker { |
35 |
| - ?method a woc:Method . |
36 |
| - ?invoker woc:requests ?method . |
| 134 | + SELECT ?method |
| 135 | + WHERE { |
| 136 | + ?method a woc:Method ; |
| 137 | + woc:hasParameter/woc:hasType woc:Double ; |
| 138 | + dul:associatedWith dbr:Cube_root . |
37 | 139 | }
|
0 commit comments