/// <exception cref="System.IO.IOException"/> /// <exception cref="System.TypeLoadException"/> /// <exception cref="System.MemberAccessException"/> /// <exception cref="System.Exception"/> /// <exception cref="Java.Util.Concurrent.ExecutionException"/> /// <exception cref="Java.Lang.InstantiationException"/> /// <exception cref="System.MissingMethodException"/> /// <exception cref="System.Reflection.TargetInvocationException"/> public virtual string SuggestPhrases() { ResetPatternLabelsInSents(Data.sents); GetPatternsFromDataMultiClass <SurfacePattern> model = new GetPatternsFromDataMultiClass <SurfacePattern>(props, Data.sents, seedWords, false, humanLabelClasses); //model.constVars.numIterationsForPatterns = 2; model.IterateExtractApply(); return(model.constVars.GetLearnedWordsAsJson()); }
/// <exception cref="System.MemberAccessException"/> /// <exception cref="System.Exception"/> /// <exception cref="Java.Util.Concurrent.ExecutionException"/> /// <exception cref="System.IO.IOException"/> /// <exception cref="Java.Lang.InstantiationException"/> /// <exception cref="System.MissingMethodException"/> /// <exception cref="System.Reflection.TargetInvocationException"/> /// <exception cref="System.TypeLoadException"/> /// <exception cref="Java.Sql.SQLException"/> public virtual string SuggestPhrasesTest(Properties testProps, string modelPropertiesFile, string stopWordsFile) { logger.Info("Suggesting phrases in test"); logger.Info("test properties are " + testProps); Properties runProps = StringUtils.ArgsToPropertiesWithResolve(new string[] { "-props", modelPropertiesFile }); string[] removeProperties = new string[] { "allPatternsDir", "storePatsForEachToken", "invertedIndexClass", "savePatternsWordsDir", "batchProcessSents", "outDir", "saveInvertedIndex", "removeOverLappingLabels", "numThreads" }; foreach (string s in removeProperties) { if (runProps.Contains(s)) { runProps.Remove(s); } } runProps.SetProperty("stopWordsPatternFiles", stopWordsFile); runProps.SetProperty("englishWordsFiles", stopWordsFile); runProps.SetProperty("commonWordsPatternFiles", stopWordsFile); runProps.PutAll(props); runProps.PutAll(testProps); props.PutAll(runProps); ProcessText(false); GetPatternsFromDataMultiClass <SurfacePattern> model = new GetPatternsFromDataMultiClass <SurfacePattern>(runProps, Data.sents, seedWords, true, humanLabelClasses); ArgumentParser.FillOptions(model, runProps); GetPatternsFromDataMultiClass.LoadFromSavedPatternsWordsDir(model, runProps); IDictionary <string, int> alreadyLearnedIters = new Dictionary <string, int>(); foreach (string label in model.constVars.GetLabels()) { alreadyLearnedIters[label] = model.constVars.GetLearnedWordsEachIter()[label].LastEntry().Key; } if (model.constVars.learn) { // Map<String, E> p0 = new HashMap<String, SurfacePattern>(); // Map<String, Counter<CandidatePhrase>> p0Set = new HashMap<String, Counter<CandidatePhrase>>(); // Map<String, Set<E>> ignorePatterns = new HashMap<String, Set<E>>(); model.IterateExtractApply(null, null, null); } IDictionary <string, ICounter <CandidatePhrase> > allExtractions = new Dictionary <string, ICounter <CandidatePhrase> >(); //Only for one label right now! string label_1 = model.constVars.GetLabels().GetEnumerator().Current; allExtractions[label_1] = new ClassicCounter <CandidatePhrase>(); foreach (KeyValuePair <string, DataInstance> sent in Data.sents) { StringBuilder str = new StringBuilder(); foreach (CoreLabel l in sent.Value.GetTokens()) { if (l.Get(typeof(PatternsAnnotations.MatchedPatterns)) != null && !l.Get(typeof(PatternsAnnotations.MatchedPatterns)).IsEmpty()) { str.Append(" " + l.Word()); } else { allExtractions[label_1].IncrementCount(CandidatePhrase.CreateOrGet(str.ToString().Trim())); str.Length = 0; } } } allExtractions.PutAll(model.matchedSeedWords); return(model.constVars.GetSetWordsAsJson(allExtractions)); }