virgil/commit

Fix drug mention count

authorMichiel Hildebrand
Sun Dec 8 17:28:13 2013 +0100
committerMichiel Hildebrand
Sun Dec 8 17:28:13 2013 +0100
commit38960dfe3232cee2f26eb7eee29cbcccf1b6179b
treeaf85804c785b498190c37c17ffb57880ed4ecacd
parent1df31eefdb01fba45f9e5d0312f2760da113c724
Diff style: patch stat
diff --git a/api/drugs.pl b/api/drugs.pl
index 51bf4fa..270635f 100644
--- a/api/drugs.pl
+++ b/api/drugs.pl
@@ -33,32 +33,30 @@ http_drug_mentions(Request) :-
 
 drug_mentions(Q, Method, Mentions) :-
 	findall(Count-M,
-		(   setof(R, drug_mention(Method, Q, M, R),
-			  Rs),
+		(   setof(R, drug_mention(Method, Q, M, R), Rs),
 		    length(Rs, Count)
 		),
 		Mentions0),
 	keysort(Mentions0, Mentions1),
 	reverse(Mentions1, Mentions).
-
 /*
 drug_mention(Method, Q, Lit, DrugUse, Report) :-
 	drug_mention(Method, Q, Lit, DrugUse),
 	rdf(Report, aers:drug, DrugUse).
 */
-
-drug_mention(exact, Q,  Lit, DrugUse) :-
+drug_mention(exact, Q,  Lit, Report) :-
 	!,
-	rdf(DrugUse, aers:drugname, literal(exact(Q), Lit)).
-drug_mention(brand, Q, Lit, DrugUse) :-
+	rdf(DrugUse, aers:drugname, literal(exact(Q), Lit)),
+	rdf(Report, aers:drug, DrugUse).
+drug_mention(brand, Q, Lit, Report) :-
 	!,
 	drug_brand_name(drugbank, Q, Brand),
-	drug_mention(word, Brand, Lit, DrugUse).
-drug_mention(synonym, Q, Lit, DrugUse) :-
+	drug_mention(word, Brand, Lit, Report).
+drug_mention(synonym, Q, Lit, Report) :-
 	!,
 	drug_synonym(drugbank, Q, Synonym),
-	drug_mention(word, Synonym, Lit, DrugUse).
-drug_mention(Method, Q,	Lit, DrugUse) :-
+	drug_mention(word, Synonym, Lit, Report).
+drug_mention(Method, Q,	Lit, Report) :-
 	(   Method = word
 	->  Query = case(Q)
 	;   Method = stem
@@ -75,7 +73,8 @@ drug_mention(Method, Q,	Lit, DrugUse) :-
 	->  corrected_match(L, Lit, DrugUse)
 	;   rdf(DrugUse, aers:drugname, literal(L)),
 	    Lit = L
-	).
+	),
+	rdf(Report, aers:drug, DrugUse).
 
 corrected_match(Name, Lit, DrugUse) :-
 	rdf(DrugUse, aers:drugname_corrected, literal(Name)),