Example #1
0
def markup_doc(doc_text: str):
    context = pyConText.ConTextDocument()
    rslts = []
    for s in doc_text.split('\.'):
        m = markup_sentence(s, modifiers=modifiers, targets=targets)
        rslts.append(m)

    for r in rslts:
        context.addMarkup(r)
    return context
def markup_doc(doc_text: str) -> pyConText.ConTextDocument:
    rslts = []
    context = pyConText.ConTextDocument()
    #for s in doc_text.split('.'):
    m = markup_sentence(doc_text, modifiers=my_modifiers, targets=my_targets)
    rslts.append(m)

    for r in rslts:
        context.addMarkup(r)
    return context
Example #3
0
def apply_context(input_context, modifier_path, target_path):
    """
    Function that applies context algorithm on patient records input.
    Returns dictionary:
    {<record number/id>:
        {
        "object" : <context document>,
        "xml" : <context as xml string>
        }
    }
    """
    print("\nNumber of patient records that will be processed:",
          len(input_context.index))

    # Obtain itemdata
    modifiers = itemData.get_items(modifier_path)
    targets = itemData.get_items(target_path)

    # Initialize context object
    context = pyConText.ConTextDocument()

    # For each patient record in the input data file:
    for record_index in input_context.index:
        record_text = input_context.at[record_index, "text"]
        record_nr = input_context.at[record_index, "record"]

        # check if record is string, otherwise skip markup for record
        if isinstance(record_text, str):
            # Apply context
            context = \
                markup_record(context, record_text, record_nr,
                              modifiers, targets)
        else:
            print(
                f"\nRecord number {record_nr} is no string. This record is skipped."
            )
        # print(f"Output dict after record: {record_nr}\n{output_dict}")
    # n_objects = len(output_dict)
    # print(f"\nOutput object contains {n_objects} context objects\n")
    return (context)
Example #4
0
def analyze_sentence(sentence, modifiers, targets, tagExperiencer=False):
    context = pyConText.ConTextDocument()
    markup = pyConText.ConTextMarkup()
    markup.setRawText(sentence)
    markup.markItems(modifiers, mode="modifier")
    markup.markItems(targets, mode="target")

    markup.pruneMarks()
    markup.dropMarks('Exclusion')
    markup.applyModifiers()

    markup.dropInactiveModifiers()
    markup.updateScopes()

    context.addMarkup(markup)
    g = context.getDocumentGraph()

    ma = g.getMarkedTargets()

    tst = []
    details = []
    found = {}
    for te in ma:
        #print ma
        tmp1, tmp2 = getNegationValue(g, te)
        if tagExperiencer:
            e1, e2 = getExperiencerValue(g, te)
            if e1 != 'Other':
                tst.append(tmp1)
                details.append(tmp2)
                found[tmp2] = Counter(tmp1)
        else:
            tst.append(tmp1)
            details.append(tmp2)
            found[tmp2] = Counter(tmp1)

    return tst, details
Example #5
0
    markup = pyConText.ConTextMarkup()
    markup.setRawText(s)
    markup.cleanText()
    markup.markItems(modifiers, mode="modifier")
    markup.markItems(targets, mode="target")
    markup.pruneMarks()
    markup.dropMarks('Exclusion')
    # apply modifiers to any targets within the modifiers scope
    markup.applyModifiers()
    markup.pruneSelfModifyingRelationships()
    if prune_inactive:
        markup.dropInactiveModifiers()
    return markup


context = pyConText.ConTextDocument()

# %%
count = 0
rslts = []
for s in sent_tokenize(reports[0]):
    m = markup_sentence(s, modifiers=modifiers, targets=targets)
    rslts.append(m)

for r in rslts:
    context.addMarkup(r)

# %%
clrs = {
    "bowel_obstruction": "blue",
    "inflammation": "blue",
Example #6
0
def markup_context(rslts):
    context = pyConText.ConTextDocument()
    for r in rslts:
        context.addMarkup(r)
    return context
 def markup_doc(doc_text: str) -> pyConText.ConTextDocument:
     rslts = []
     context = pyConText.ConTextDocument()