コード例 #1
0
ファイル: NERHelper.cs プロジェクト: derekantrican/NERWrapper
        public void LoadClassifier(string classifierPath)
        {
            if (!File.Exists(classifierPath))
            {
                throw new FileNotFoundException($"Could not find the path `{classifierPath}`");
            }

            this.classifier = CRFClassifier.getClassifier(classifierPath);
        }
コード例 #2
0
    void Start()
    {
        singleton = this;
        if (!System.IO.File.Exists(model))
        {
            throw new Exception($"Check path to the model file '{model}'");
        }

        // Load our custom directional classifier
        spatialClassifier = CRFClassifier.getClassifier(customModelDirectory + @"/spatialDirectionModel.gaz.ser.gz");

        // Loading POS Tagger
        MaxentTagger tagger = new MaxentTagger(model);

        var sentences = MaxentTagger.tokenizeText(new java.io.StringReader(input)).toArray();

        foreach (java.util.ArrayList sentence in sentences)
        {
            var taggedSentence = tagger.tagSentence(sentence);
            Debug.Log(SentenceUtils.listToString(taggedSentence, false));
            debugDisplay.text = (SentenceUtils.listToString(taggedSentence, false));

            String previousNoun     = null;
            String connectingPhrase = "";
            foreach (var x in taggedSentence.toArray())
            {
                String taggedWord = x.ToString();
                String word       = taggedWord.Split('/').FirstOrDefault();

                if (taggedWord.Contains("/NN") &&
                    false == (spatialClassifier as CRFClassifier).classifyToString($"{connectingPhrase} {word}")
                    ?.Split(' ').Where(s => !s.Contains("/0")).Where(s2 => s2.Split('/').First() == word).Any())
                {
                    nounStack    += ((nounStack.ToArray().Any()) ? " " : "") + word;
                    lastIsPlural |= taggedWord.Contains("/NNS");
                }
                else
                {
                    if (nounStack != "")
                    {
                        var id = getModelId(nounStack);
                        Debug.Log($"Found id for {nounStack}");
                        debugDisplay.text = $"Found id for {nounStack}";

                        if (id != null)
                        {
                            sceneObjects.Add(new sceneObject(nounStack, id, lastIsPlural, (previousNoun == null), !sceneObjects.Where(s => s.name == nounStack).Any(), parseDirection(previousNoun, connectingPhrase)));
                        }

                        connectingPhrase = "";
                        previousNoun     = word;
                        nounStack        = "";
                    }
                    connectingPhrase += ((!connectingPhrase.ToCharArray().Any()) ? "" : " ") + word;
                }
            }

            if (nounStack != "")
            {
                var id = getModelId(nounStack);
                Debug.Log($"Found id for {nounStack}");
                debugDisplay.text = $"Found id for {nounStack}";

                if (id != null)
                {
                    sceneObjects.Add(new sceneObject(nounStack, id, lastIsPlural, (previousNoun == null), !sceneObjects.Where(s => s.name == nounStack).Any(), parseDirection(previousNoun, connectingPhrase)));
                }
            }
        }
        // Once we have all our ids start downloading the models
        // download = https://archive3d.net/?a=download&do=get&id={modelId}

        // Set up dictonary of locations

        var uniqueOnes = sceneObjects.Where(u => u.unique);

        foreach (var sceneObj in uniqueOnes)
        {
            sceneObject.namedModels.Add(sceneObj.name, null);
        }

        DownloadFiles();
        beginCheck = true;
    }