コード例 #1
0
 public static void Main(string[] args)
 {
     try
     {
         Properties props = StringUtils.ArgsToPropertiesWithResolve(args);
         ArgumentParser.FillOptions(typeof(GoogleNGramsSQLBacked), props);
         Connect();
         //if(populateTables)
         //  populateTablesInSQL(dataDir, ngramsToPopulate);
         //testing
         System.Console.Out.WriteLine("For head,the count is " + GetCount("head"));
         //System.out.println(getCount("what the heck"));
         //System.out.println(getCount("my name is john"));
         System.Console.Out.WriteLine(GetCounts(Arrays.AsList("cancer", "disease")));
         System.Console.Out.WriteLine("Get count 1 gram " + GetTotalCount(1));
         if (props.GetProperty("phrase") != null)
         {
             string p = props.GetProperty("phrase");
             System.Console.Out.WriteLine("count for phrase " + p + " is " + GetCount(p));
         }
         if (props.GetProperty("rank") != null)
         {
             string p = props.GetProperty("rank");
             System.Console.Out.WriteLine("Rank of " + p + " is " + Get1GramRank(p));
         }
         CloseConnection();
     }
     catch (Exception e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
     }
 }
コード例 #2
0
 public static void Main(string[] args)
 {
     try
     {
         LearnImportantFeatures lmf   = new LearnImportantFeatures();
         Properties             props = StringUtils.ArgsToPropertiesWithResolve(args);
         ArgumentParser.FillOptions(lmf, props);
         lmf.SetUp();
         string sentsFile = props.GetProperty("sentsFile");
         IDictionary <string, DataInstance> sents = IOUtils.ReadObjectFromFile(sentsFile);
         System.Console.Out.WriteLine("Read the sents file: " + sentsFile);
         double perSelectRand = double.Parse(props.GetProperty("perSelectRand"));
         double perSelectNeg  = double.Parse(props.GetProperty("perSelectNeg"));
     }
     catch (Exception e)
     {
         // String wekaOptions = props.getProperty("wekaOptions");
         //lmf.getTopFeatures(false, , perSelectRand, perSelectNeg, props.getProperty("externalFeatureWeightsFile"));
         Sharpen.Runtime.PrintStackTrace(e);
     }
 }
コード例 #3
0
        /// <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));
        }