示例#1
0
        /// <summary>
        /// The stage two exploration
        /// </summary>
        /// <param name="lemma">The lemma.</param>
        /// <param name="response">The response.</param>
        /// <param name="savemodel">if set to <c>true</c> [savemodel].</param>
        /// <param name="debug">if set to <c>true</c> [debug].</param>
        /// <param name="verbose">if set to <c>true</c> [verbose].</param>
        /// <returns></returns>
        public static termExploreModelSet exploreStageTwo(string lemma, ILogBuilder response, bool savemodel, bool debug, bool verbose, lexiconTaskBase task = null)
        {
            lexiconConstructor  constructor = semanticLexiconManager.manager.constructor;
            termExploreModelSet outset      = semanticLexiconManager.manager.constructor.loadTermModels(lemma, true);

            if (!Enumerable.Any(outset))
            {
                outset.missingLemmas.Add(lemma);
                return(outset);
            }

            foreach (termExploreModel mod in outset)
            {
                builderForLog logout = new builderForLog();
                if (verbose)
                {
                    aceLog.consoleControl.setAsOutput(logout, "stage2");
                }
                termExploreModel model = getSynonymsWithApertium(mod, logout);

                string pt = model.lemma.gramSet.getPosType().ToString();
                if (savemodel)
                {
                    //  model.graph.saveDescription(constructor.projectFolderStructure[lexiconConstructorProjectFolder.logs].path, pt + "_related");
                }


                model = getSynonymsWithWordnetViaApertium(model, logout, true, false);

                if (savemodel)
                {
                    model.graph.saveDescription(constructor.projectFolderStructure[lexiconConstructorProjectFolder.logs].path, pt + "_concepts");
                    // model.graph.savePaths(constructor.projectFolderStructure[lexiconConstructorProjectFolder.logs].path, pt + "_concepts");
                }


                model.PostProcess();

                if (debug)
                {
                    model.ToString(logout, true, true);
                    string fn = model.lemma.inputForm + "_" + pt + "_log.md";
                    logout.ToString(false).saveStringToFile(constructor.projectFolderStructure[lexiconConstructorProjectFolder.logs].pathFor(fn), getWritableFileMode.overwrite);
                }

                if (verbose)
                {
                    aceLog.consoleControl.removeFromOutput(logout);
                }

                if (savemodel)
                {
                    if (task != null)
                    {
                        model.lastModifiedByStage = task.taskTitle;
                    }
                    else
                    {
                        model.lastModifiedByStage = "stageTwo-exploreProcedure";
                    }
                    if (!model.wasExploreFailed)
                    {
                        constructor.saveTermModel(model);
                    }
                    else
                    {
                        outset.failedModels.Add(model);
                    }
                }
            }
            return(outset);
        }
示例#2
0
        public static termExploreModel explore(string word, ILogBuilder response, termExploreMode mode, bool verbose = false)
        {
            termExploreModel    model  = new termExploreModel(word);
            termExploreModelSet outset = semanticLexiconManager.manager.constructor.loadTermModels(word, true);

            if (response != null)
            {
                response.consoleAltColorToggle();
                response.AppendHorizontalLine();
                response.AppendLine("Exploring term[" + model.inputForm + "] with [" + mode.ToString() + "]");
                response.consoleAltColorToggle();
            }

            if (Enumerable.Any(outset))
            {
                model = Enumerable.First(outset);

                if (response != null)
                {
                    response.AppendLine("term[" + model.inputForm + "]->lemma[" + model.lemma.inputForm + "]");
                }
            }
            else
            {
                model.lemmaForm = "";
                if (response != null)
                {
                    response.AppendLine("term[" + word + "]->missingLemma[]");
                }
            }


            var output = response;

            if (!verbose)
            {
                response = null;
            }

            switch (mode)
            {
            case termExploreMode.apertium_direct:
                model = getSynonymsWithApertium(model, response);
                break;

            case termExploreMode.apertium_wordnet_eng:
                model = getSynonymsWithWordnetViaApertium(model, response);
                break;

            case termExploreMode.apertium_wordnet_srb:
                model = getSynonymsWithSerbianWordNetAndApertium(model, response);
                break;

            case termExploreMode.corpus:
                model = getSynonymsByCorpus(model, response);
                break;

            case termExploreMode.hunspell_srb:
                model = getSynonymsWithHunspell(model, response);
                break;

            case termExploreMode.none:
                break;

            case termExploreMode.wordnet_srb:
                model = getSynonymsWithSerbianWordNet(model, response);
                break;

            case termExploreMode.unitex:
                model = exploreWithUnitex(word, response);
                break;
            }

            model.PostProcess();
            if (output != null)
            {
                model.ToString(output, verbose, false);
            }

            return(model);
        }