Exemplo n.º 1
0
        public List <WordObject> getWordsObjectFromParserServer(String str)
        {
            List <WordObject> sentenceFromServer = new List <WordObject>();
            var res = new List <WordObject>();

            try
            {
                string JsonRes = HttpCtrl.sendToHebrewMorphAnalizer(str);

                if (JsonRes != null && JsonRes != "")
                {
                    sentenceFromServer = JsonConvert.DeserializeObject <List <WordObject> >(JsonRes);
                }

                //may be mispelling for the first time


                var firstWord = true;
                // print tagged sentence by using AnalysisInterface, as follows:
                foreach (WordObject w in sentenceFromServer)
                {
                    WordObject word = w;

                    //two NRI in a row
                    //join word if ist part of a name
                    if (res.Count > 0)
                    {
                        var last = res.LastOrDefault();
                        if (((last.Ner == word.Ner && last.Ner != "O") || (last.isA(properNameWord) && word.isA(properNameWord))) &&
                            !word.Prefixes.Contains("ו") && !firstWord)
                        {
                            res.LastOrDefault().Text  = res.LastOrDefault().Text.Remove(0, res.LastOrDefault().Prefixes.Count());
                            res.LastOrDefault().Text += " " + word.Text;
                            res.LastOrDefault().Lemma = res.LastOrDefault().Text;
                            continue;
                        }
                    }
                    firstWord = false;
                    res.Add(w);
                }
            }
            catch (Exception ex) //if parser server is down
            {
                var words = str.Split(' ');
                foreach (var w in words)
                {
                    var word = new WordObject(w, nounWord);
                    sentenceFromServer.Add(word);
                }
            }

            return(res);
        }
Exemplo n.º 2
0
        public virtual List <List <WordObject> > meniAnalize(String str, bool isUserInput)
        {
            List <List <WordObject> > allRes = new List <List <WordObject> >();

            if (str != null)
            {
                str = str.Trim();
                if (str != null && str.Length > 0)
                {
                    if (isUserInput)
                    {
                        var correctSpelling = HttpCtrl.correctSpelling(str);
                        if (correctSpelling != null)
                        {
                            str = correctSpelling.Replace("\\", "");
                        }
                    }


                    var strRes = removeParentheses(str, '(', ')');
                    strRes = removeParentheses(strRes, '[', ']');
                    var sentenceFromServer = getWordsObjectFromParserServer(strRes);


                    if (sentenceFromServer != null && sentenceFromServer.Count >= 0)
                    {
                        var allText           = splitByLine(sentenceFromServer);
                        List <WordObject> res = null;
                        foreach (var sentence in allText)
                        {
                            res = new List <WordObject>();
                            if (sentence != null && sentence.Count >= 0)
                            {
                                //remove nikod etc.s
                                var firstWord = true;
                                // print tagged sentence by using AnalysisInterface, as follows:
                                foreach (WordObject w in sentence)
                                {
                                    WordObject word = w;
                                    //         if (hebDictionary.contains(w.Text))
                                    //       {
                                    //              word = hebDictionary.get(word.Text);
                                    //         }

                                    //joinwords
                                    //if (res.LastOrDefault() != null && word.isA(nounWord) && res.LastOrDefault().isA(nounWord))
                                    //{
                                    //    var last = res.LastOrDefault();
                                    //    res.RemoveAt(res.Count - 1);
                                    //    last.Text = last.Text + " " + word.Text;
                                    //    last.WordT = last.WordT | word.WordT; //combin flages
                                    //    word = last;
                                    //}

                                    res.Add(word);
                                }
                                res.RemoveAll(x => (x.Text.Length <= 1) && (x.Pos == "punctuation") && (x.Text != "|"));
                                res = tryMatchEntities(res, isUserInput);
                            }

                            // res = checkPhrases(res);

                            allRes.Add(res);
                        }
                    }
                }
            }
            return(allRes);
        }