Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' of https://github.com/ClarityNLP/ClarityNLP in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
richardboyd committed Aug 26, 2019
2 parents 3bfa930 + add2928 commit 0558fe1
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nlp/nlpql/nlpql.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ def run_nlpql_parser(nlpql_txt: str):


if __name__ == '__main__':
with open('samples/simple.nlpql') as f:
with open('samples/sample2.nlpql') as f:
nlpql_txt = f.read()
results = run_nlpql_parser(nlpql_txt)
if results['has_errors'] or results['has_warnings']:
Expand Down
3 changes: 2 additions & 1 deletion nlp/nlpql/nlpql_parser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ unaryOperator:

logicalOperator:
AND |
OR
OR |
NOT
;

comparisonOperator:
Expand Down
2 changes: 1 addition & 1 deletion nlp/nlpql/nlpql_parser.interp

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions nlp/nlpql/nlpql_parserParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def serializedATN():
buf.write("\n,\3-\3-\3-\3-\3-\3-\3-\3-\3-\3-\3-\3-\5-\u0187\n-\3")
buf.write("-\2\4\60\66.\2\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"")
buf.write("$&(*,.\60\62\64\668:<>@BDFHJLNPRTVX\2\n\4\2\"\"PP\4\2")
buf.write("#$PP\3\2&\'\4\2++\65\65\3\2)*\3\2\4\5\4\2\"\"UU\6\2\t")
buf.write("#$PP\3\2&\'\4\2++\65\65\3\2)+\3\2\4\5\4\2\"\"UU\6\2\t")
buf.write("\t\f\30\33\35\37!\2\u019f\2]\3\2\2\2\4p\3\2\2\2\6t\3\2")
buf.write("\2\2\bv\3\2\2\2\ny\3\2\2\2\f|\3\2\2\2\16~\3\2\2\2\20\u0083")
buf.write("\3\2\2\2\22\u0086\3\2\2\2\24\u008b\3\2\2\2\26\u0093\3")
Expand Down Expand Up @@ -2033,6 +2033,9 @@ def AND(self):
def OR(self):
return self.getToken(nlpql_parserParser.OR, 0)

def NOT(self):
return self.getToken(nlpql_parserParser.NOT, 0)

def getRuleIndex(self):
return nlpql_parserParser.RULE_logicalOperator

Expand All @@ -2048,7 +2051,7 @@ def logicalOperator(self):
self.enterOuterAlt(localctx, 1)
self.state = 283
_la = self._input.LA(1)
if not(_la==nlpql_parserParser.AND or _la==nlpql_parserParser.OR):
if not((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << nlpql_parserParser.AND) | (1 << nlpql_parserParser.OR) | (1 << nlpql_parserParser.NOT))) != 0)):
self._errHandler.recoverInline(self)
else:
self._errHandler.reportMatch(self)
Expand Down
File renamed without changes.
76 changes: 76 additions & 0 deletions nlp/nlpql/samples/sample2.nlpql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
limit 100;
phenotype "Test Setdiff" version "1";
include ClarityCore version "1.0" called Clarity;
///////////////////////////////////////////////////////////////////////////////
//
// Documents
//
///////////////////////////////////////////////////////////////////////////////
// documentset Docs:
// Clarity.createDocumentSet({
// "report_types":[
// "Physician",
// "Nurse",
// "Note",
// "Discharge Summary"
// ],
// "source":"MIMIC"
// });
///////////////////////////////////////////////////////////////////////////////
//
// Termsets
//
///////////////////////////////////////////////////////////////////////////////
termset RigorsTerms: [
"Rigors",
"Rigoring",
"Shivers",
"Shivering"
];
termset DyspneaTerms: [
"Labored respiration",
"Shortness of breath",
"Short of breath",
"SOB",
"Respiration labored",
"Labored breathing",
"Dyspnea",
"Difficulty breathing"
];
///////////////////////////////////////////////////////////////////////////////
//
// Provider Assertions
//
///////////////////////////////////////////////////////////////////////////////
define hasRigors:
Clarity.ProviderAssertion({
termset: [RigorsTerms]
});
define hasDyspnea:
Clarity.ProviderAssertion({
termset: [DyspneaTerms]
});

///////////////////////////////////////////////////////////////////////////////
//
// Context
//
///////////////////////////////////////////////////////////////////////////////
context Patient;
///////////////////////////////////////////////////////////////////////////////
//
// Expressions
//
///////////////////////////////////////////////////////////////////////////////
define RigorsOrDyspnea:
where hasRigors OR hasDyspnea;
define RigorsAndDyspnea:
where hasRigors AND hasDyspnea;
define hasRigorsOrDyspneaButNotBoth:
where (hasRigors OR hasDyspnea) NOT (hasRigors AND hasDyspnea);
define complexNotLogic:
where (hasTachycardia OR hasShock OR hasRigors) NOT ( (hasTachycardia AND hasShock) OR (hasTachycardia AND hasRigors) OR (hasShock AND hasRigors) );
define LogicAndMath1:
where (hasRigors OR hasDyspnea OR hasTachycardia) NOT ( (Temperature.value >= 100.4) AND (Temperature.value <= 102) );
define LogicAndMath2:
where (Lesion.dimension_X > 10 AND Lesion.dimension_X < 30) NOT (hasRigors OR hasTachycardia OR hasDyspnea);
4 changes: 2 additions & 2 deletions nlp/tasks/TermFinderTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def run_term_finder(name, filters, pipeline_config, temp_file, mongo_client, doc

for doc in docs:
objs = get_cached_terms(name, doc[util.solr_report_id_field], pipeline_config.terms, pipeline_config.
synonyms, pipeline_config
.descendants, pipeline_config.ancestors, pipeline_config
include_synonyms, pipeline_config
.include_descendants, pipeline_config.include_ancestors, pipeline_config
.vocabulary, filters, has_special_filters)
if objs and len(objs) > 0:
for obj in objs:
Expand Down

0 comments on commit 0558fe1

Please sign in to comment.