Skip to content

Commit

Permalink
Merge pull request #393 from DigitalSlideArchive/match-methods
Browse files Browse the repository at this point in the history
Make it clearer to adjust API match methods.
  • Loading branch information
manthey authored Nov 10, 2023
2 parents a0910bf + 1e534c0 commit a164923
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/test_seer_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_api_search(api_search):
queries = api_search.getOCRQueryList(ocr_record)

# Ensure each query has enough data
assert all([len(query) >= 3 for query in queries])
assert all([len(query) >= 2 for query in queries])

# Ensure tokens with confidence < .5 aren't used for queries
query_tokens_list = [list(query.values()) for query in queries]
Expand Down
15 changes: 12 additions & 3 deletions wsi_deid/matching_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ class APISearch:
},
}

apiMatchMethods = [
{'path_case_num', 'name_last', 'name_first', 'date_of_birth'},
{'path_case_num', 'name_last', 'name_first'},
{'path_case_num', 'name_last', 'date_of_birth'},
{'path_case_num', 'name_first', 'date_of_birth'},
{'path_case_num', 'name_last', 'name_first', 'date_of_service'},
{'name_last', 'name_first', 'date_of_birth'},
{'path_case_num', 'name_last'},
{'path_case_num', 'date_of_birth'},
]

confidenceThreshold = 0.50

def __init__(self, url=None, apikey=None, logger=None):
Expand Down Expand Up @@ -115,9 +126,7 @@ def getQueryList(self, words):
if v is not None and (v['word'], v['value']) not in used:
params[k] = v['value']
used.add((v['word'], v['value']))
if (len(params) >= 3 and (
params.get('name_first') or params.get('name_last')) and (
params.get('date_of_birth') or params.get('path_case_num'))):
if any(not len(apiset - set(params)) for apiset in self.apiMatchMethods):
if params not in [entry[-1] for entry in queries]:
queries.append((-len(params), len(queries), params))
queries = [entry[-1] for entry in sorted(queries)]
Expand Down
12 changes: 3 additions & 9 deletions wsi_deid/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,8 @@ def callMatchingAPI(self, match):
)
@access.public
def fakeMatchingAPI(self, match): # noqa
from .matching_api import APISearch

fakeData = []
try:
filepath = '/conf/fake_matches.json'
Expand All @@ -873,16 +875,8 @@ def fakeMatchingAPI(self, match): # noqa
fakeData = json.load(open(filepath))
except Exception:
pass
matchMethods = [
{'date_of_birth', 'name_last', 'name_first', 'path_case_num'},
{'name_last', 'name_first', 'path_case_num'},
{'date_of_birth', 'name_last', 'path_case_num'},
{'date_of_birth', 'name_first', 'path_case_num'},
{'date_of_birth', 'name_last', 'name_first', 'date_of_service'},
{'date_of_birth', 'name_last', 'name_first'},
]
results = []
for matchMethod in matchMethods:
for matchMethod in APISearch.apiMatchMethods:
for entry in fakeData:
matched = True
try:
Expand Down

0 comments on commit a164923

Please sign in to comment.