Ejemplo n.º 1
0
 def load(
     cls,
     path_to_quickumls: str,
     accepted_semtypes: Optional[Set[str]] = None,
     threshold: float = 0.9,
     similarity_name: str = "jaccard",
     spacy_string: str = "en_core_sci_sm",
     best_match: bool = False,
     n_workers: int = 1,
 ) -> "QuickUMLSClassifier":
     if accepted_semtypes is None:
         accepted_semtypes = ALL_SEMTYPES
     q = QuickUMLS(path_to_quickumls,
                   accepted_semtypes=accepted_semtypes,
                   threshold=threshold,
                   similarity_name=similarity_name)
     # Load the spacy model, Disable the NER and Parser.
     q.nlp = spacy.load(spacy_string, disable=("ner", "parser"))
     return cls(q, n_workers)
Ejemplo n.º 2
0
    def load(
        cls,
        path_to_quickumls: str,
        accepted_semtypes: Optional[Set[str]] = None,
        threshold: float = 0.9,
        similarity_name: str = "jaccard",
        pooling: str = "mean",
        spacy_string: str = "en_core_sci_sm",
        priors: Optional[Dict[str, float]] = None,
        n_workers: int = 1,
    ) -> "QuickUMLSClassifier":
        """
        Load a QuickUMLSClassifier instance.

        :param path_to_quickumls: The path to a valid quickUMLS installation.
        :param accepted_semtypes: A set of accepted semantic types. If this is None, we revert to all semantic types.
        :param threshold: The threshold to accept.
        :param similarity_name: The name of the similarity function. Accepted are 'jaccard', 'overlap', 'cosine' and 'dice'.
        :param pooling: The name of the pooling function to use. Should be 'mean', 'max' or 'sum'.
        :param spacy_string: The string of the spacy model to use.
        :param priors: None or a dictionary mapping from semantic types to class probabilities.
        :param n_workers: The number of workers to use during prediction.
        :return: An initialized QuickUMLSClassifier.
        """
        # Fail early
        if pooling not in cls.FUNCS:
            raise ValueError(
                f"mode should be in {cls.FUNCS}, is now {pooling}")

        if accepted_semtypes is None:
            accepted_semtypes = ALL_SEMTYPES

        q = QuickUMLS(path_to_quickumls,
                      accepted_semtypes=accepted_semtypes,
                      threshold=threshold,
                      similarity_name=similarity_name)
        # Load the spacy model, Disable the NER and Parser.
        q.nlp = spacy.load(spacy_string, disable=("ner", "parser"))
        return cls(q, pooling, priors, n_workers)