Example #1
0
        private void InitIndex()
        {
            IndexClear();

            foreach (XmlNode paraXn in m_xmlRoot.ChildNodes)
            {
                XmlElement paraXe    = (XmlElement)paraXn;
                ParaIndex  paragraph = new ParaIndex();
                paragraph.GlobalSentenceStartId = m_listSentences.Count;
                foreach (XmlNode senXn in paraXe.ChildNodes)
                {
                    XmlElement senXe    = (XmlElement)senXn;
                    SentIndex  sentence = new SentIndex();
                    foreach (XmlNode wordXn in senXe.ChildNodes)
                    {
                        sentence.WordList.Add(new Word((XmlElement)wordXn));
                    }
                    sentence.XmlElem    = senXe;
                    sentence.StrContent = senXe.GetAttribute("cont");
                    paragraph.SentenceList.Add(sentence);
                    m_listSentences.Add(sentence);
                }

                paragraph.XmlElem = paraXe;
                m_listParas.Add(paragraph);
            }
        }
Example #2
0
        public void AddSentence(String strSentence, int paragraphIdx)
        {
            if (m_bIsOverAdd)
            {
                return;
            }

            if (true == HasSent() && (true == HasWS() || true == HasPOS() ||
                                      true == HasNE() || true == HasWSD() || true == HasSRL())
                )
            {
                throw new Exception(LtpServiceError.AddSentenceNoteMissMatchError);
            }

            m_xmlNote.SetAttribute(LTPTag.NOTE_SENT, "y");

            SetParagraphNumber(paragraphIdx + 1);

            XmlElement xmlParaElement = m_listParas[paragraphIdx].XmlElem;

            XmlNode      xmlSentNode        = m_xmlDocument.CreateNode(XmlNodeType.Element, "sent", "");
            XmlAttribute xmlSentIdAttribute = m_xmlDocument.CreateAttribute("id");

            xmlSentIdAttribute.Value = m_listParas[paragraphIdx].SentenceList.Count.ToString();
            xmlSentNode.Attributes.Append(xmlSentIdAttribute);
            XmlAttribute xmlSentContAttribute = m_xmlDocument.CreateAttribute("cont");

            xmlSentContAttribute.Value = strSentence;
            xmlSentNode.Attributes.Append(xmlSentContAttribute);
            xmlParaElement.AppendChild(xmlSentNode);

            SentIndex sentIndexCur = new SentIndex();

            sentIndexCur.StrContent = strSentence;
            sentIndexCur.XmlElem    = (XmlElement)xmlSentNode;
            int globalSentenceId = m_listParas[paragraphIdx].GlobalSentenceStartId + m_listParas[paragraphIdx].SentenceList.Count;

            m_listParas[paragraphIdx].SentenceList.Add(sentIndexCur);
            m_listSentences.Insert(globalSentenceId, sentIndexCur);
            for (int i = paragraphIdx + 1; i < m_listParas.Count; i++)
            {
                m_listParas[i].GlobalSentenceStartId++;
            }
        }
Example #3
0
        public void AddSentence(List<Word> wordList, int paragraphIdx)
        {
            if (wordList.Count == 0 || m_bIsOverAdd)
            {
                return;
            }

            if (true == HasSent() && false == HasWS() && false == HasPOS()
                && false == HasNE() && false == HasWSD() && false == HasSRL()
               )
            {
                throw new Exception(LtpServiceError.AddSentenceNoteMissMatchError);
            }

            if (m_listParas.Count == 0)
            {
                Word w = wordList[0];
                // if the xmlDocument is empty, paragraphIdx should be zero
                m_xmlNote.SetAttribute(LTPTag.NOTE_SENT, "y");
                if (w.HasWS())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_WORD, "y");
                }
                if (w.HasPOS())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_POS, "y");
                }
                if (w.HasNE())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_NE, "y");
                }
                if (w.HasWSD())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_WSD, "y");
                }
                if (w.HasParser())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_PARSER, "y");
                }
            }
            String strSentence = String.Empty;
            foreach (Word w in wordList)
            {
                if (CheckWordMatch(w) == false)
                {
                    return;
                    //throw new Exception("AddSentence error: Some word's attribute mismatch !");
                }
                strSentence = strSentence + w.XmlElem.GetAttribute("cont");
            }

            SetParagraphNumber(paragraphIdx + 1);

            XmlElement xmlParaElement = m_listParas[paragraphIdx].XmlElem;

            XmlNode xmlSentNode = m_xmlDocument.CreateNode(XmlNodeType.Element, "sent", "");
            XmlAttribute xmlSentIdAttribute = m_xmlDocument.CreateAttribute("id");
            xmlSentIdAttribute.Value = m_listParas[paragraphIdx].SentenceList.Count.ToString();
            xmlSentNode.Attributes.Append(xmlSentIdAttribute);
            XmlAttribute xmlSentContAttribute = m_xmlDocument.CreateAttribute("cont");
            xmlSentContAttribute.Value = strSentence;
            xmlSentNode.Attributes.Append(xmlSentContAttribute);
            xmlParaElement.AppendChild(xmlSentNode);

            SentIndex sentIndexCur = new SentIndex();
            sentIndexCur.StrContent = strSentence;
            sentIndexCur.XmlElem = (XmlElement)xmlSentNode;
            int globalSentenceId = m_listParas[paragraphIdx].GlobalSentenceStartId + m_listParas[paragraphIdx].SentenceList.Count;
            m_listParas[paragraphIdx].SentenceList.Add(sentIndexCur);
            m_listSentences.Insert(globalSentenceId, sentIndexCur);
            for (int i = paragraphIdx + 1; i < m_listParas.Count; i++)
            {
                m_listParas[i].GlobalSentenceStartId++;
            }

            int length = wordList.Count;
            for (int i = 0; i < length; i++)
            {
                XmlNode wordNode = m_xmlDocument.CreateNode(XmlNodeType.Element, "word", "");
                xmlSentNode.AppendChild(wordNode);
                XmlElement wordElem = (XmlElement)wordNode;
                wordElem.SetAttribute("id", i.ToString());
                Word curWord = new Word(wordElem);
                if (HasWS())
                {
                    wordElem.SetAttribute(LTPTag.CONT, wordList[i].GetWS());
                }
                if (HasPOS())
                {
                    wordElem.SetAttribute(LTPTag.POS, wordList[i].GetPOS());
                }
                if (HasNE())
                {
                    wordElem.SetAttribute(LTPTag.NE, wordList[i].GetNE());
                }
                if (HasParser())
                {
                    wordElem.SetAttribute(LTPTag.PSR_PARENT, "" + wordList[i].GetParserParent());
                    wordElem.SetAttribute(LTPTag.PSR_RELATE, wordList[i].GetParserRelation());
                }
                if (HasWSD())
                {
                    wordElem.SetAttribute(LTPTag.WSD, wordList[i].GetWSD());
                    wordElem.SetAttribute(LTPTag.WSD_EXP, wordList[i].GetWSDExplanation());
                }
                curWord.SetSRL(wordList[i].GetSRLs());

                m_listSentences[globalSentenceId].WordList.Add(curWord);
            }
        }
Example #4
0
        private void InitIndex()
        {
            IndexClear();

            foreach(XmlNode paraXn in m_xmlRoot.ChildNodes)
            {
                XmlElement paraXe = (XmlElement)paraXn;
                ParaIndex paragraph = new ParaIndex();
                paragraph.GlobalSentenceStartId = m_listSentences.Count;
                foreach(XmlNode senXn in paraXe.ChildNodes)
                {
                    XmlElement senXe = (XmlElement)senXn;
                    SentIndex sentence = new SentIndex();
                    foreach(XmlNode wordXn in senXe.ChildNodes)
                    {
                        sentence.WordList.Add(new Word((XmlElement)wordXn));
                    }
                    sentence.XmlElem = senXe;
                    sentence.StrContent = senXe.GetAttribute("cont");
                    paragraph.SentenceList.Add(sentence);
                    m_listSentences.Add(sentence);
                }

                paragraph.XmlElem = paraXe;
                m_listParas.Add(paragraph);
            }
        }
Example #5
0
        public void AddSentence(String strSentence, int paragraphIdx)
        {
            if (m_bIsOverAdd)
            {
                return;
            }

            if (true == HasSent() && (true == HasWS() || true == HasPOS() ||
                true == HasNE() || true == HasWSD() || true == HasSRL())
                )
            {
                throw new Exception(LtpServiceError.AddSentenceNoteMissMatchError);
            }

            m_xmlNote.SetAttribute(LTPTag.NOTE_SENT, "y");

            SetParagraphNumber(paragraphIdx + 1);

            XmlElement xmlParaElement = m_listParas[paragraphIdx].XmlElem;

            XmlNode xmlSentNode = m_xmlDocument.CreateNode(XmlNodeType.Element, "sent", "");
            XmlAttribute xmlSentIdAttribute = m_xmlDocument.CreateAttribute("id");
            xmlSentIdAttribute.Value = m_listParas[paragraphIdx].SentenceList.Count.ToString();
            xmlSentNode.Attributes.Append(xmlSentIdAttribute);
            XmlAttribute xmlSentContAttribute = m_xmlDocument.CreateAttribute("cont");
            xmlSentContAttribute.Value = strSentence;
            xmlSentNode.Attributes.Append(xmlSentContAttribute);
            xmlParaElement.AppendChild(xmlSentNode);

            SentIndex sentIndexCur = new SentIndex();
            sentIndexCur.StrContent = strSentence;
            sentIndexCur.XmlElem = (XmlElement)xmlSentNode;
            int globalSentenceId = m_listParas[paragraphIdx].GlobalSentenceStartId + m_listParas[paragraphIdx].SentenceList.Count;
            m_listParas[paragraphIdx].SentenceList.Add(sentIndexCur);
            m_listSentences.Insert(globalSentenceId, sentIndexCur);
            for (int i = paragraphIdx + 1; i < m_listParas.Count; i++)
            {
                m_listParas[i].GlobalSentenceStartId++;
            }
        }
Example #6
0
        public void AddSentence(List <Word> wordList, int paragraphIdx)
        {
            if (wordList.Count == 0 || m_bIsOverAdd)
            {
                return;
            }

            if (true == HasSent() && false == HasWS() && false == HasPOS() &&
                false == HasNE() && false == HasWSD() && false == HasSRL()
                )
            {
                throw new Exception(LtpServiceError.AddSentenceNoteMissMatchError);
            }

            if (m_listParas.Count == 0)
            {
                Word w = wordList[0];
                // if the xmlDocument is empty, paragraphIdx should be zero
                m_xmlNote.SetAttribute(LTPTag.NOTE_SENT, "y");
                if (w.HasWS())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_WORD, "y");
                }
                if (w.HasPOS())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_POS, "y");
                }
                if (w.HasNE())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_NE, "y");
                }
                if (w.HasWSD())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_WSD, "y");
                }
                if (w.HasParser())
                {
                    m_xmlNote.SetAttribute(LTPTag.NOTE_PARSER, "y");
                }
            }
            String strSentence = String.Empty;

            foreach (Word w in wordList)
            {
                if (CheckWordMatch(w) == false)
                {
                    return;
                    //throw new Exception("AddSentence error: Some word's attribute mismatch !");
                }
                strSentence = strSentence + w.XmlElem.GetAttribute("cont");
            }

            SetParagraphNumber(paragraphIdx + 1);

            XmlElement xmlParaElement = m_listParas[paragraphIdx].XmlElem;

            XmlNode      xmlSentNode        = m_xmlDocument.CreateNode(XmlNodeType.Element, "sent", "");
            XmlAttribute xmlSentIdAttribute = m_xmlDocument.CreateAttribute("id");

            xmlSentIdAttribute.Value = m_listParas[paragraphIdx].SentenceList.Count.ToString();
            xmlSentNode.Attributes.Append(xmlSentIdAttribute);
            XmlAttribute xmlSentContAttribute = m_xmlDocument.CreateAttribute("cont");

            xmlSentContAttribute.Value = strSentence;
            xmlSentNode.Attributes.Append(xmlSentContAttribute);
            xmlParaElement.AppendChild(xmlSentNode);

            SentIndex sentIndexCur = new SentIndex();

            sentIndexCur.StrContent = strSentence;
            sentIndexCur.XmlElem    = (XmlElement)xmlSentNode;
            int globalSentenceId = m_listParas[paragraphIdx].GlobalSentenceStartId + m_listParas[paragraphIdx].SentenceList.Count;

            m_listParas[paragraphIdx].SentenceList.Add(sentIndexCur);
            m_listSentences.Insert(globalSentenceId, sentIndexCur);
            for (int i = paragraphIdx + 1; i < m_listParas.Count; i++)
            {
                m_listParas[i].GlobalSentenceStartId++;
            }

            int length = wordList.Count;

            for (int i = 0; i < length; i++)
            {
                XmlNode wordNode = m_xmlDocument.CreateNode(XmlNodeType.Element, "word", "");
                xmlSentNode.AppendChild(wordNode);
                XmlElement wordElem = (XmlElement)wordNode;
                wordElem.SetAttribute("id", i.ToString());
                Word curWord = new Word(wordElem);
                if (HasWS())
                {
                    wordElem.SetAttribute(LTPTag.CONT, wordList[i].GetWS());
                }
                if (HasPOS())
                {
                    wordElem.SetAttribute(LTPTag.POS, wordList[i].GetPOS());
                }
                if (HasNE())
                {
                    wordElem.SetAttribute(LTPTag.NE, wordList[i].GetNE());
                }
                if (HasParser())
                {
                    wordElem.SetAttribute(LTPTag.PSR_PARENT, "" + wordList[i].GetParserParent());
                    wordElem.SetAttribute(LTPTag.PSR_RELATE, wordList[i].GetParserRelation());
                }
                if (HasWSD())
                {
                    wordElem.SetAttribute(LTPTag.WSD, wordList[i].GetWSD());
                    wordElem.SetAttribute(LTPTag.WSD_EXP, wordList[i].GetWSDExplanation());
                }
                curWord.SetSRL(wordList[i].GetSRLs());

                m_listSentences[globalSentenceId].WordList.Add(curWord);
            }
        }