Example #1
0
        static void Main()
        {
            var jarRoot         = @"C:\Users\Burds\Downloads\Stanford.NLP.NET-master (1)\Stanford.NLP.NET-master\samples\Stanford.NLP.POSTagger.CSharp\bin\Debug\stanford-postagger-2018-02-27";
            var modelsDirectory = jarRoot + @"\models";

            // Loading POS Tagger
            var tagger = new MaxentTagger(modelsDirectory + @"\english-left3words-distsim.tagger");

            // Text for tagging
            var text = "This is a test sentence.";

            string[] arr       = new string[10];
            var      sentences = MaxentTagger.tokenizeText(new StringReader(text)).toArray();

            string[] getType = new string[10];
            foreach (ArrayList sentence in sentences)
            {
                var taggedSentence = tagger.tagSentence(sentence);
                Console.WriteLine(SentenceUtils.listToString(taggedSentence, false));
                var data = new List <DataClass>();

                for (int i = 0; i < taggedSentence.size() - 1; i++)
                {
                    string myString = taggedSentence.get(i).ToString();

                    data.Add(new DataClass
                    {
                        SWord = sentence.get(i).ToString(),
                        WType = myString.Substring(myString.IndexOf("/") + 1)
                    });
                    //getType[i] = myString.Substring(myString.IndexOf("/") + 1);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            // Loading POS Tagger
            var tagger = new MaxentTagger(@"Resources/english-bidirectional-distsim.tagger");

            // Text for tagging
            //var text = @"یک روز آمدم ";
            var text = "hello how are you?";
            IList <Tuple <string, string> > tagged = new List <Tuple <string, string> >();


            var sentences = MaxentTagger.tokenizeText(new StringReader(text)).toArray();

            foreach (ArrayList sentence in sentences)
            {
                var taggedSentence = tagger.tagSentence(sentence);
                System.Console.WriteLine(SentenceUtils.listToString(taggedSentence, false));

                for (int i = 0; i < taggedSentence.size(); i++)
                {
                    var t = taggedSentence.toArray()[i].ToString().Split('/');
                    tagged.Add(Tuple.Create(t[0], t[1]));
                }
            }
        }
Example #3
0
        private void TagReader(Reader reader)
        {
            var sentences = MaxentTagger.tokenizeText(reader).toArray();

            Assert.NotNull(sentences);

            foreach (ArrayList sentence in sentences)
            {
                var tSentence = _tagger.tagSentence(sentence);
                TestContext.Out.WriteLine(SentenceUtils.listToString(tSentence, false));
            }
        }
Example #4
0
        public string send(string text)
        {
            string[] exampleWords = text.Split(
                new char[] { ' ', ',', '.', ')', '(' }, StringSplitOptions.RemoveEmptyEntries);

            ILemmatizer lmtz = new LemmatizerPrebuiltCompact(LemmaSharp.LanguagePrebuilt.English);

            StringBuilder sb = new StringBuilder();

            foreach (string word in exampleWords)
            {
                sb.Append(LemmatizeOne(lmtz, word) + " ");
            }

            string finalstring = sb.ToString();


            var jarRoot         = @"E:\stanford-postagger-full-2015-12-09\stanford-postagger-full-2015-12-09";
            var modelsDirectory = jarRoot + @"\models";
            // Loading POS Tagger
            var tagger = new MaxentTagger(modelsDirectory + @"\wsj-0-18-bidirectional-nodistsim.tagger");

            // Text for tagging
            StringBuilder str = new StringBuilder();

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

            foreach (ArrayList sentence in sentences)
            {
                var    taggedSentence = tagger.tagSentence(sentence);
                string sent           = SentenceUtils.listToString(taggedSentence, false);

                String[] tokens = sent.Split(' ');
                for (int i = 0; i < tokens.Length; i++)
                {
                    if (tokens[i].Contains("/VB"))
                    {
                        str.Append(tokens[i] + " ");
                    }
                }
            }
            return(str.ToString());
        }
Example #5
0
        static void Main()
        {
            var jarRoot         = @"..\..\..\..\data\paket-files\nlp.stanford.edu\stanford-postagger-full-2018-10-16";
            var modelsDirectory = jarRoot + @"\models";

            // Loading POS Tagger
            var tagger = new MaxentTagger(modelsDirectory + @"\wsj-0-18-bidirectional-nodistsim.tagger");

            // Text for tagging
            var text = "A Part-Of-Speech Tagger (POS Tagger) is a piece of software that reads text in some language "
                       + "and assigns parts of speech to each word (and other token), such as noun, verb, adjective, etc., although "
                       + "generally computational applications use more fine-grained POS tags like 'noun-plural'.";

            var sentences = MaxentTagger.tokenizeText(new StringReader(text)).toArray();

            foreach (ArrayList sentence in sentences)
            {
                var taggedSentence = tagger.tagSentence(sentence);
                Console.WriteLine(SentenceUtils.listToString(taggedSentence, false));
            }
        }
Example #6
0
        public List <TargetCandidate> GetAllNounPhrases(string[] sentence, string[] target)
        {
            var tree         = lexParser.apply(SentenceUtils.toCoreLabelList(sentence));
            var dependencies = grammaticalStructureFactory.newGrammaticalStructure(tree).typedDependenciesCCprocessed();

            List <TargetCandidate> nounPhrases = new List <TargetCandidate>();

            var subTrees = tree.subTreeList();

            for (int i = 0; i < subTrees.size(); i++)
            {
                Tree subTree = (Tree)subTrees.get(i);
                if (subTree.label().value() == "NP")
                {
                    NounPhrase phrase = NounPhrase.SetSentence(sentence, tree, dependencies, target);
                    phrase.SetPhrase(SentenceUtils.listToString(subTree.yield()));
                    nounPhrases.Add(new TargetCandidate(phrase, caching));
                }
            }

            return(nounPhrases);
        }
Example #7
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;
    }
Example #8
0
        public String getParse(String ask)
        {
            String directories;

            directories = System.IO.Directory.GetCurrentDirectory();


            List <object>    NP              = new List <object>();
            var              jarRoot         = directories + @"\stanford-postagger-2018-02-27";
            var              modelsDirectory = jarRoot + @"\models";
            List <DataClass> newdata         = new List <DataClass>();
            // Loading POS Tagger
            var tagger = new MaxentTagger(modelsDirectory + @"\english-left3words-distsim.tagger");
            var data   = new List <DataClass>();

            // Text for tagging
            var text = ask;

            string[] arr       = new string[10];
            var      sentences = MaxentTagger.tokenizeText(new StringReader(text)).toArray();

            string[] getType   = new string[10];
            String   tagString = "";

            foreach (ArrayList sentence in sentences)
            {
                var taggedSentence = tagger.tagSentence(sentence);
                Console.WriteLine(SentenceUtils.listToString(taggedSentence, false));
                tagString = string.Join(" ", taggedSentence);

                for (int i = 0; i <= taggedSentence.size() - 1; i++)
                {
                    String myString = taggedSentence.get(i).ToString();

                    data.Add(new DataClass
                    {
                        SWord = sentence.get(i).ToString(),
                        WType = myString.Substring(myString.IndexOf("/") + 1)
                    });
                    //getType[i] = myString.Substring(myString.IndexOf("/") + 1);
                }
            }
            //int k = 0;
            String outStr = "";

            String[] locations = { "Pasig", "Manila", "Laguna de Bay", "Philippines", "Marikina" };
            for (int k = 0; k <= data.Count - 1; k++)
            {
                if (locations.Contains(data[k].SWord) && data[k + 1].WType != "NNP")
                {
                    data[k].WType = "LC";
                }
                outStr = outStr + data[k].SWord + "/" + data[k].WType;
                // k++;
            }
            //String[] locations = { "Pasig", "Manila", "Laguna de Bay", "Philippines", "Marikina" };

            String outPut = "[" + outStr + "]";

            // return s;
            return(tagString);
        }
Example #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            //-----------------RSQ-------Requirement Sentence Quality----------------------------------------
            string location = "C:/Users/PRATHYUSH/Desktop/text.txt";

            System.IO.StreamWriter file = new System.IO.StreamWriter(location);

            file.WriteLine("------------------Requirement Sentence Quality---------------------");
            var jarRoot         = @"C:\Users\PRATHYUSH\Desktop\project files\stanford-postagger-full-2018-10-16";
            var modelsDirectory = jarRoot + @"\models";

            // Loading POS Tagger
            var tagger = new MaxentTagger(modelsDirectory + @"\wsj-0-18-bidirectional-nodistsim.tagger");

            //----------------------------------------------------------------------------------------------------
            string FilePath = path;
            string FileText = new System.IO.StreamReader(FilePath).ReadToEnd();

            string[] SentenceArray = FileText.Split('.', '!', '?');

            //string arrays containing the necessary words
            string[] ImplicitWords  = { "this", "This", "these", "These", "that", "those", "it", "they", "they", "above", "below", "previous", "next", "following", "last", "and first" };
            string[] OptionalWords  = { "can", "eventually", "if appropriate", "if needed", "may", "optionally", "possibly" };
            string[] VagueWords     = { "adequate", "back", "bad", "clear", "close", "easy", "efficient", "far", "fast", "future", "good", "in front", "low", "near", "new", "old", "past", "recent", "significant", "slow", "strong", "today’s", "useful", "weak", "and well" };
            string[] WeakWords      = { "as a minimum", "as applicable", "as appropriate", "be able to", "be capable", "not limited to", "the capability of", "the capability to", "easy", "effective", "if practical", "normal", "provide for", "to be determined", "and timely" };
            string[] DirectiveWords = { "figures", "for example", "table", "note", "i.e.", "e.g." };
            string[] Continuances   = { "below", "as follows", "following", "listed", "in particular", "support", "and" };
            string[] imperatives    = { "Shall", "shall", "Must", "must", "is required to", "Are Applicable", "Are to", "are to", "Responsible for", "will", "should" };

            for (int i = 0; i < SentenceArray.Length; i++)
            {
                file.WriteLine(" ");
                file.WriteLine("Sentence {0}", i + 1);
                file.WriteLine(SentenceArray[i]);


                file.WriteLine("------ Multiple Sentence ------ ");

                object[] sentences = MaxentTagger.tokenizeText(new StringReader(SentenceArray[i])).toArray();
                foreach (ArrayList sentence in sentences)
                {
                    var taggedSentence = tagger.tagSentence(sentence);
                    file.WriteLine(SentenceUtils.listToString(taggedSentence, false));

                    var             myRegX = new Regex("/V");
                    MatchCollection m      = myRegX.Matches(SentenceUtils.listToString(taggedSentence, false));
                    if (m.Count > 0)
                    {
                        file.WriteLine("Verb Count - " + m.Count);
                    }
                }


                file.WriteLine("------ Implicit Words ------ ");
                for (int j = 0; j < ImplicitWords.Length; j++)
                {
                    var             myRegEx = new Regex("\\b" + ImplicitWords[j] + "\\b");
                    MatchCollection matches = myRegEx.Matches(SentenceArray[i]);
                    int             impword = matches.Count;
                    imp = impword + imp;
                    if (matches.Count > 0)
                    {
                        file.WriteLine(ImplicitWords[j] + " - " + matches.Count + " times");
                    }
                }


                file.WriteLine("------ Optional Words ------ ");
                for (int j = 0; j < OptionalWords.Length; j++)
                {
                    var             myRegEx = new Regex("\\b" + OptionalWords[j] + "\\b");
                    MatchCollection matches = myRegEx.Matches(SentenceArray[i]);
                    int             optword = matches.Count;
                    opt = optword + opt;
                    if (matches.Count > 0)
                    {
                        file.WriteLine(OptionalWords[j] + " - " + matches.Count + " times");
                    }
                }


                file.WriteLine("------ Vague Words ------ ");
                for (int j = 0; j < VagueWords.Length; j++)
                {
                    var             myRegEx = new Regex("\\b" + VagueWords[j] + "\\b");
                    MatchCollection matches = myRegEx.Matches(SentenceArray[i]);
                    int             vagword = matches.Count;
                    vague = vagword + vague;
                    if (matches.Count > 0)
                    {
                        file.WriteLine(VagueWords[j] + " - " + matches.Count + " times");
                    }
                }


                file.WriteLine("------ Weak Words ------ ");
                for (int j = 0; j < WeakWords.Length; j++)
                {
                    var             myRegEx = new Regex("\\b" + WeakWords[j] + "\\b");
                    MatchCollection matches = myRegEx.Matches(SentenceArray[i]);
                    int             Weword  = matches.Count;
                    weak = Weword + weak;
                    if (matches.Count > 0)
                    {
                        file.WriteLine(WeakWords[j] + " - " + matches.Count + " times");
                    }
                }


                file.WriteLine("------ Directive Words ------ ");
                for (int j = 0; j < DirectiveWords.Length; j++)
                {
                    var             myRegEx = new Regex("\\b" + DirectiveWords[j] + "\\b");
                    MatchCollection matches = myRegEx.Matches(SentenceArray[i]);
                    int             diwords = matches.Count;
                    direct = diwords + direct;
                    if (matches.Count > 0)
                    {
                        file.WriteLine(DirectiveWords[j] + " - " + matches.Count + " times");
                    }
                }

                file.WriteLine("------ Continuance Words ------ ");
                for (int j = 0; j < Continuances.Length; j++)
                {
                    var             myRegEx   = new Regex("\\b" + Continuances[j] + "\\b");
                    MatchCollection matches   = myRegEx.Matches(SentenceArray[i]);
                    int             contwords = matches.Count;
                    cont = contwords + cont;
                    if (matches.Count > 0)
                    {
                        file.WriteLine(Continuances[j] + " - " + matches.Count + " times");
                    }
                }

                file.WriteLine("------ imperatives ------ ");
                for (int j = 0; j < imperatives.Length; j++)
                {
                    var             myRegEx    = new Regex("\\b" + imperatives[j] + "\\b");
                    MatchCollection matches    = myRegEx.Matches(SentenceArray[i]);
                    int             imptawords = matches.Count;
                    impta = imptawords + impta;
                    if (matches.Count > 0)
                    {
                        file.WriteLine(imperatives[j] + " - " + matches.Count + " times");
                    }
                }
            }
            file.WriteLine("------------ ");
            file.WriteLine("------ Total tally ------ ");
            file.WriteLine("DirectiveWords" + " - " + direct + " times");
            file.WriteLine("weak words" + " - " + weak + " times");
            file.WriteLine("vague words" + " - " + vague + " times");
            file.WriteLine("optional words" + " - " + opt + " times");
            file.WriteLine("implicit words" + " - " + imp + " times");
            file.WriteLine("continuance words" + " - " + cont + " times");
            file.WriteLine("imperative words" + " - " + impta + " times");



            //-------------------------RDQ------Requirement Document Quality-----------------------------------------
            file.WriteLine("\r\n\r\n------------Requirement Document Quality-------------\r\n \r\n");
            double LinesCount;
            int    CharCount;
            double WordsCount;
            string Path = path;
            string Text = new System.IO.StreamReader(Path).ReadToEnd();



            CharCount = Text.Trim().Length;                     //total char

            LinesCount = Text.Split('.', '!', '?').Length;      //total lines


            WordsCount = Text.Split(' ').Length;               // total Words


            file.WriteLine("Character count is {0} \r\n", CharCount);
            file.WriteLine("Word count is {0} \r\n", WordsCount);
            file.WriteLine("Line count is {0} \r\n", LinesCount);


            //finding the number of syllables
            string contents = System.IO.File.ReadAllText(path);
            int    SCount   = SyllableCount(contents);

            file.WriteLine("Syllable count is {0} \r\n", SCount);

            //finding the Flesch index
            file.WriteLine("finding the Flesch index: \r\n");
            double ASL = WordsCount / LinesCount;

            file.WriteLine("Average Sentence Length");
            file.WriteLine("{0}\r\n", ASL);
            double ASW = SCount / WordsCount;

            file.WriteLine("Average number of syllables per word");
            file.WriteLine("{0}\r\n", ASW);

            double FRI = 206.835 - (1.015 * ASL) - (84.6 * ASW);

            file.WriteLine("The Flesch index is");
            file.WriteLine("{0}\r\n", FRI);
            //printinh the ranges for flesch index value
            file.WriteLine("Flesch index ranges:\r\n \r\n100 - 90 \t very easy to read (5th grade) \r\n90 – 80 \t easy to read (6th grade) \r\n80 – 70 \t fairly easy to read (7th grade) \r\n70 – 60 \t plain english (8th & 9th grade) \r\n60 – 50 \t fairly difficult to read (10th - 12th grade) \r\n50 – 30 \t difficult to read (College) \r\n30 – 0  \t very difficult to read (College graduate) \r\n\r\n");


            //finding the Automatic Readabilty index
            file.WriteLine("finding the Automatic readabilty index:\r\n");
            double AVL = CharCount / WordsCount;

            file.WriteLine("the average number of letters per word");
            file.WriteLine("{0}\r\n", AVL);
            double AVW = WordsCount / LinesCount;

            file.WriteLine("the average number of words in sentences");
            file.WriteLine("{0}\r\n", AVW);
            double ARI = (AVL * 4.71) + (AVW * 0.5) - 21.43;

            file.WriteLine("The Automatic readability index is");
            file.WriteLine("{0}\r\n", ARI);
            file.WriteLine("Automatic redability index ranges:\r\n \r\n10 - 11	\tFifth Grade. \r\n11 - 12 \tSixth Grade. \r\n12 - 13 \tSeventh Grade. \r\n13 - 14 \tEighth Grade. \r\n14 - 15 \tNinth Grade. \r\n15 - 16 \tTenth Grade. \r\n16 - 17 \tEleventh grade. \r\n17 - 20 \tTwelfth grade. \r\n20 - 24 \tCollege. \r\n24 - 27 \tCollege graduate.");



            file.Flush();
            file.Close();
            System.Console.WriteLine("The output is stored in the file {0}", location);
        }