示例#1
0
        public static void TestPurePython()
        {
            // Initialization required
            Nltk.Init(new List <string>
            {
                @"C:\IronPython27\Lib",
                @"C:\IronPython27\Lib\site-packages",
            });


            // Imports NLTK corpus module
            Nltk.Py.ImportModule("nltk.corpus");

            // Import 'names' object to access corpus content
            Nltk.Py.ExecuteScript("from nltk.corpus import names");

            // Get object by name
            dynamic namesObj = Nltk.Py.GetObject("names");

            // Call object's method 'names.words()'
            dynamic namesList = Nltk.Py.CallMethod(namesObj, "words");

            foreach (var name in namesList)
            {
                Console.Write(name + ", ");
            }
        }
示例#2
0
        public static void OverallTest()
        {
            Nltk.Init(new List <string>()
            {
                @"C:\IronPython27\Lib",
                @"C:\IronPython27\Lib\site-packages",
            });

            TestImport();
            TestStandard();
        }
示例#3
0
        static void TestNameEntityRecognizer()
        {
            string text = "WASHINGTON -- In the wake of a string of abuses by New York police officers in the 1990s, Loretta E. Lynch, " +
                          "the top federal prosecutor in Brooklyn, spoke forcefully about the pain of a broken trust that African-Americans " +
                          "felt and said the responsibility for repairing generations of miscommunication and mistrust fell to law enforcement.";

            var tokens         = Nltk.Tokenize.WordTokenize(text);
            var posTaggedWords = Nltk.PosTag(tokens.AsNet);

            // NOTE: This operation requires NumPy library for IronPython
            var neChunks = Nltk.NeChunk(posTaggedWords);

            BuiltIns.Print($"NER output for text: '{text}'");
            BuiltIns.Print(neChunks);
        }
示例#4
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Task.Run(() =>
            {
                Log("Nltk.Init() Begin");

                Nltk.Init(new List <string>
                {
                    @"C:\IronPython27\Lib",
                    @"C:\IronPython27\Lib\site-packages",
                });

                Log("Nltk.Init() Done");
            });
        }
示例#5
0
        static void Main(string[] args)
        {
            Nltk.Init(new List <string>
            {
                @"C:\IronPython27\Lib",
                @"C:\IronPython27\Lib\site-packages",
            });


            //TestCorpus.TestBrown();

            TestPosTagger();

            //TestNltkResultClass();
            //TestTokenize();
            //TestProbability();
            //TestStem();

            //Workarounds.TestPurePython();
        }