GithubHelp home page GithubHelp logo

Comments (3)

khuynh11 avatar khuynh11 commented on July 20, 2024

With the warning, we are able to see the characters that may need to be preprocessed but it is not always mandatory / necessary. The idea is to log this information to alert the user (we display the ascii conversion made during regexpmatcher operation) but it may be not blocking if these characters are not used in the rules.

If you want to make the conversion yourself to have more control or because your rules are based on some specific characters, you can preprocess the text before using regexpmatcher. In your example, quotes and degree may be managed in a preprocessing step..

Here is a code example with the preprocessing in medkit:

from medkit.core.text import TextDocument
from spacy import displacy
from medkit.text.spacy.displacy_utils import medkit_doc_to_displacy
import json
f = open('trainset.json')

data = json.load(f)

from medkit.text.ner import RegexpMatcher, RegexpMatcherRule

regexp_rules = [
    RegexpMatcherRule(regexp=r"\binsuffisance r.nale\b", label="phenotype"),
]

regexp_matcher = RegexpMatcher(rules=regexp_rules)

from medkit.text.preprocessing import Normalizer, NormalizerRule, QUOTATION_RULES

preprocessing_rules = QUOTATION_RULES
preprocessing_rules.append(NormalizerRule("Ā°", "deg"))

preprocessing_op = Normalizer(output_label="clean_segment", rules=preprocessing_rules)

colors = {'phenotype': "#85C1E9"}
options = {"ents": ['phenotype'], "colors": colors}

for i in range(0, len(data)):
    s = ' '.join(data[i]['token'])
    #s = str(s).encode(encoding = 'ascii', errors = 'replace')
    #s = str(s)
    doc = TextDocument(text=s)
    normalized_segments = preprocessing_op.run([doc.raw_segment])
    entities = regexp_matcher.run(normalized_segments)
    if(len(entities)>0):
        for entity in entities:
            doc.add_annotation(entity)
        displacy_data = medkit_doc_to_displacy(doc)
        displacy.render(displacy_data, manual=True, style="ent", options=options)
        break

The quotes are already proposed / managed in medkit with QUOTATION_RULES but degree has not been integrated because it is the same character as number (nĀ°).

If you have suggestion on how it can be more managed in medkit, we are open to improvements.

from medkit.

BastienRance avatar BastienRance commented on July 20, 2024

Thank you @khuynh11 , this is a great solution !

from medkit.

khuynh11 avatar khuynh11 commented on July 20, 2024

Thanks for your feedback, I close the issue.

from medkit.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.