16
17:- module(wikidata,
18 [
19
20 property_constraint_pv/4,
21
22 var_drug_condition/4,
23
24 enlabel/2,
25 enlabelp/2,
26 enlabel_any/2,
27 exact_match/2
28
29 ]). 30
31:- use_module(library(sparqlprog)). 32:- use_module(library(semweb/rdf11)). 33
34:- sparql_endpoint( wd, 'http://query.wikidata.org/sparql'). 35
36:- rdf_register_prefix(foaf,'http://xmlns.com/foaf/0.1/'). 37:- rdf_register_prefix(dbont,'http://dbpedia.org/ontology/'). 39:- rdf_register_prefix(wikipathways,'http://vocabularies.wikipathways.org/wp#'). 40:- rdf_register_prefix(obo,'http://purl.obolibrary.org/obo/'). 41:- rdf_register_prefix(so,'http://purl.obolibrary.org/obo/SO_'). 42
44:- rdf_register_prefix(wd,'http://www.wikidata.org/entity/'). 45:- rdf_register_prefix(wdt,'http://www.wikidata.org/prop/direct/'). 46:- rdf_register_prefix(wbont,'http://wikiba.se/ontology#'). 47
48:- rdf_register_prefix(instance_of,'http://www.wikidata.org/prop/direct/P31'). 49
50user:term_expansion(pname_wid(P,Id),
51 [( Head :- Body),
52 ( Head_trans :- Body_trans),
53 ( Head_s :- Body_s),
54 ( Head_ps :- Body_ps),
55 ( Head_q :- Body_q),
56 ( Head_iri :- true),
57 ( Head_eiri :- true),
58 ( :- initialization(export(P_trans/2), now)),
59 ( :- initialization(export(P_s/2), now)),
60 ( :- initialization(export(P_ps/2), now)),
61 ( :- initialization(export(P_q/2), now)),
62 ( :- initialization(export(P_iri/1), now)),
63 ( :- initialization(export(P_eiri/1), now)),
64 ( :- initialization(export(P/2), now))
65 ]) :-
66
67 68 upcase_atom(Id,Frag),
69
70
71 72 73 Head =.. [P,S,O],
74 atom_concat('http://www.wikidata.org/prop/direct/',Frag,Px),
75 Body = rdf(S,Px,O),
76
77 atom_concat(P,'_transitive',P_trans),
78 Head_trans =.. [P_trans,S,O],
79 Body_trans = rdf_path(S,zeroOrMore(Px),O),
80
81
82 83 84 atom_concat(P,'_e2s',P_s),
85 Head_s =.. [P_s,S,O],
86 atom_concat('http://www.wikidata.org/prop/',Frag,Px_s),
87 Body_s = rdf(S,Px_s,O),
88
89 atom_concat(P,'_iri',P_iri),
90 Head_iri =.. [P_iri,Px],
91
92 atom_concat('http://www.wikidata.org/entity/',Frag,Pe),
93 atom_concat(P,'_eiri',P_eiri),
94 Head_eiri =.. [P_eiri,Pe],
95
96 97 98 atom_concat(P,'_s2v',P_ps),
99 Head_ps =.. [P_ps,S,O],
100 atom_concat('http://www.wikidata.org/prop/statement/',Frag,Px_ps),
101 Body_ps = rdf(S,Px_ps,O),
102
103 104 105 106 atom_concat(P,'_s2q',P_q),
107 Head_q =.. [P_q,S,O],
108 atom_concat('http://www.wikidata.org/prop/qualifier/',Frag,Px_q),
109 Body_q = rdf(S,Px_q,O).
110
111
112
113user:term_expansion(cname_wid(C,Id),
114 [Rule,
115 RuleInf,
116 RuleIsa,
117 ( Head_iri :- true),
118 (:- initialization(export(InfC/1), now)),
119 (:- initialization(export(SubC/1), now)),
120 (:- initialization(export(C_iri/1), now)),
121 (:- initialization(export(C/1), now))
122 ]) :-
123 upcase_atom(Id,Frag),
124 atom_concat('http://www.wikidata.org/entity/',Frag,Cx),
125
126 Head =.. [C,I],
127 Body = rdf(I,'http://www.wikidata.org/prop/direct/P31',Cx),
128 Rule = (Head :- Body),
129
130 atom_concat(C,'_iri',C_iri),
131 Head_iri =.. [C_iri,Cx],
132
133 atom_concat(C,'_inf',InfC),
134 Head2 =.. [InfC,I],
135 Body2 = rdf(I,('http://www.wikidata.org/prop/direct/P31'/zeroOrMore('http://www.wikidata.org/prop/direct/P279')),Cx),
136 RuleInf = (Head2 :- Body2),
137
138 atom_concat('isa_',C,SubC),
139 Head3 =.. [SubC,I],
140 Body3 = rdf(I,zeroOrMore('http://www.wikidata.org/prop/direct/P279'),Cx),
141 RuleIsa = (Head3 :- Body3).
142
143
144enlabel(E,N) :- label(E,N),lang(N)="en".
145enlabelp(E,N) :- rdf(X,wbont:directClaim,E),enlabel(X,N).
146enlabel_any(E,N) :- enlabel(E,N).
147enlabel_any(E,N) :- enlabelp(E,N).
148
149
150
154
156
160
164
166subproperty_of(S,O) :- rdf(S,'http://www.wikidata.org/prop/direct/P1647',O).
168
171
174
175
176
178
180pname_wid(instance_of, p31).
181pname_wid(subclass_of, p279).
182pname_wid(equivalent_property, p1628).
183pname_wid(property_constraint, p2302).
184
185property_constraint_pv(P,C,PP,V) :-
186 property_constraint_e2s(P,S),
187 rdf(S,PP,V),
188 property_constraint_s2v(S,C).
189
191pname_wid(author, p50).
192pname_wid(exact_match, p2888).
193
195pname_wid(coordinate_location, p625).
196
199pname_wid(hp_id, p3841).
200pname_wid(envo_id, p3859).
201pname_wid(doid_id, p699).
202pname_wid(chebi_id, p683).
203pname_wid(uniprot_id, p352).
204pname_wid(ncbigene_id, p351).
205pname_wid(ipr_id, p2926).
206pname_wid(civic_id, p3329).
207pname_wid(ro_id, p3590).
208pname_wid(mesh_id, p486).
209pname_wid(go_id, p686).
210pname_wid(ncbitaxon_id, p685).
211pname_wid(uberon_id, p1554).
212pname_wid(umls_id, p2892).
213
215pname_wid(encodes, p688).
216pname_wid(genetic_association, p2293).
217pname_wid(treated_by_drug, p2176).
218pname_wid(symptoms, p780).
219pname_wid(pathogen_transmission_process, p1060).
220pname_wid(has_cause, p828).
221pname_wid(biological_variant_of, p3433).
222pname_wid(has_part, p527).
223
225pname_wid(positive_therapeutic_predictor, p3354).
226pname_wid(negative_therapeutic_predictor, p3355).
227pname_wid(positive_diagnostic_predictor, p3356).
228pname_wid(negative_diagnostic_predictor, p3357).
229pname_wid(positive_prognostic_predictor, p3358).
230pname_wid(negative_prognostic_predictor, p3359).
231pname_wid(medical_condition_treated, p2175).
232
234pname_wid(physically_interacts_with, p129).
235pname_wid(location, p276).
236pname_wid(manifestation_of, p1557).
237pname_wid(part_of, p361).
238pname_wid(followed_by, p156).
239pname_wid(product_or_material_produced, p1056).
240pname_wid(uses, p2283).
241pname_wid(has_effect, p1542).
242pname_wid(drug_used_for_treatment, p2176).
243pname_wid(found_in_taxon, p703).
244pname_wid(ortholog, p684).
245pname_wid(biological_process, p682).
246pname_wid(cell_component, p681).
247pname_wid(molecular_function, p680).
248pname_wid(has_quality, p1552).
249pname_wid(regulates, p128).
250
251
252
254
256cname_wid(geographic_entity, q27096213).
257cname_wid(continent, q5107).
258cname_wid(country, q6256).
259cname_wid(city, q515).
260pname_wid(population, p1082).
261pname_wid(part_of_continent, p30).
262
263
265cname_wid(cancer, q12078).
266cname_wid(disease, q12136).
267cname_wid(infectious_disease, q18123741).
268
269cname_wid(chemical_compound, q11173).
270cname_wid(chemical_element, q11344).
271cname_wid(drug, q12140).
272
273cname_wid(symptom, q169872).
274cname_wid(medical_finding, q639907).
275cname_wid(trait, q1211967).
276cname_wid(pathway, q4915012).
277cname_wid(macromolecular_complex, qQ22325163).
278cname_wid(gene, qQ7187).
279cname_wid(gene_product, qQ424689).
280cname_wid(sequence_variant, qQ15304597).
281
282cname_wid(therapy, q179661).
283cname_wid(medical_procedure, qQ796194).
284
285
287cname_wid(power_station, q159719).
288
290nary(ptp_var_drug_condition, positive_therapeutic_predictor, medical_condition_treated).
291
292
293
294var_drug_condition(V,D,C,positive_therapeutic_predictor) :-
295 positive_therapeutic_predictor_e2s(V,S),
296 medical_condition_treated_s2q(S,C),
297 positive_therapeutic_predictor_s2v(S,D)