Skip to content

Commit

Permalink
Merge pull request #112 from OHDSI/release-1.4.2
Browse files Browse the repository at this point in the history
Release 1.4.2
  • Loading branch information
Maxim Moinat authored Mar 15, 2021
2 parents 80df517 + 08fd549 commit 0d157f4
Show file tree
Hide file tree
Showing 9 changed files with 375 additions and 152 deletions.
37 changes: 35 additions & 2 deletions src/org/ohdsi/usagi/UsagiSearchEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public int getTermCount() {
}

public List<ScoredConcept> search(String searchTerm, boolean useMlt, Collection<Integer> filterConceptIds, Vector<String> filterDomains, Vector<String> filterConceptClasses,
Vector<String> filterVocabularies, boolean filterStandard, boolean includeSourceConcepts) {
Vector<String> filterVocabularies, boolean filterStandard, boolean includeSourceConcepts) {
List<ScoredConcept> results = new ArrayList<ScoredConcept>();
try {
Query query;
Expand Down Expand Up @@ -406,7 +406,7 @@ else if (arg1.term.toLowerCase().equals(arg1.concept.conceptName.toLowerCase()))
/**
* Lucene's matching score does some weird things: it is not normalized (the value can be greater than 1), and not all tokens are included in the
* computation. For that reason, we're recomputing the matching score as plain TF*IDF cosine matching here.
*
*
* @param scoreDocs
* The array of documents scored by Lucene
* @param query
Expand Down Expand Up @@ -438,6 +438,39 @@ public int compare(ScoreDoc arg0, ScoreDoc arg1) {
}
}

public List<String> searchConceptSynonymsByConceptId(int conceptId) {
return searchTermsByConceptId(conceptId, CONCEPT_TERM);
}

public List<String> searchSourceSynonymsByConceptId(int conceptId) {
return searchTermsByConceptId(conceptId, SOURCE_TERM);
}

private List<String> searchTermsByConceptId(int conceptId, String termType) {
List<String> result = new ArrayList<>();
try {
QueryParser keywordsQueryParser = new QueryParser(Version.LUCENE_4_9, "CONCEPT_ID", new KeywordAnalyzer());
Query conceptIdQuery = keywordsQueryParser.parse(String.valueOf(conceptId));
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(conceptIdQuery, Occur.MUST);

QueryParser termTypeQueryParser = new QueryParser(Version.LUCENE_4_9, "TERM_TYPE", new KeywordAnalyzer());
Query termTypeQuery = termTypeQueryParser.parse(termType);
booleanQuery.add(termTypeQuery, Occur.MUST);

TopDocs topDocs = searcher.search(booleanQuery, 100);
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
Document document = reader.document(scoreDoc.doc);
String term = document.get("TERM");
result.add(term);
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
return result;
}

public static class ScoredConcept {
public float matchScore;
public Concept concept;
Expand Down
Loading

0 comments on commit 0d157f4

Please sign in to comment.