public static List <SentenceMap> BuildFromMessage(Message message) { List <SentenceMap> sentlist = new List <SentenceMap>(); if (message.SentencesLength == 0) { return(sentlist); } for (int i = 0; i < message.SentencesLength; i++) { SentenceMap resSent = null; var sent = message.Sentences(i); if (sent.HasValue) { var sentval = sent.Value; resSent = new SentenceMap(); resSent._phID = sentval.SentenceID; var wlist = WordMap.GetWordsFromMessSentence(sentval); foreach (var w in wlist) { resSent.words.Add(w.Key, w.Value); } var nlist = GetNodesFromMessSentence(sentval); foreach (var node in nlist) { resSent.treeList.Add(node.Value); } sentlist.Add(resSent); } } return(sentlist); }
/// <summary> /// Запиcь в хранилище предложения новой структуры синтана этого предложения. /// </summary> public void AddSentStruct(int order, SentenceMap sentstruct) { var sprop = new SentProps(); sprop.order = order; sentstruct.ParagraphID = this.ParagraphID; sentstruct.Order = order; sprop.sentstruct = new SentenceMap(sentstruct); innerPara.Add(sprop); }
/// <summary> /// Запиcь в хранилище предложения новой структуры синтана этого предложения. /// </summary> public void UpdateSentStruct(int order, SentenceMap sentstruct) { var sent = innerPara.Where(x => x.order == order).FirstOrDefault(); if (sent.sentstruct == null) { sentstruct.ParagraphID = this.ParagraphID; sentstruct.Order = order; sent.sentstruct = new SentenceMap(sentstruct); } sent.IsActual = true; }
/// <summary> /// Конструктор - копировщик. /// </summary> public SentenceMap(SentenceMap map) { this._phID = map._phID; this._pg_id = map._pg_id; this._order = map._order; this._created_at = map._created_at; foreach (var w in map.words) { this.words.Add(w.Key, w.Value); } this.treeList.AddRange(map.treeList); }
/// <summary> /// Обновление элемента хранения предложения. /// </summary> public void RefreshSentProp(string sentence, SentenceMap sentstruct, bool IsActual) { int order = sentstruct.Order; SentProps sprop = innerPara.Where(x => x.order == order).FirstOrDefault(); if (sprop == null) { sprop = new SentProps(); sprop.order = order; innerPara.Add(sprop); } if (sprop.sentstruct == null) { sprop.sentstruct = new SentenceMap(sentstruct); } sprop.sentence = sentence; sprop.hash = sentence.GetHashCode(); sprop.IsActual = true; }
private static Offset <Sentence> BuildSingleFlatSent(FlatBufferBuilder builder, SentenceMap sentence, int order) { // Чтение слов var words = new Offset <Lexema> [sentence.Capasity]; for (int i = 0; i < sentence.Capasity; i++) { var word = sentence.GetWordByOrder(i); var EntryName = builder.CreateString(word.EntryName); var RealWord = builder.CreateString(word.RealWord); // Чтение граммем var pairs = word.GetPairs(); var grammems = new Offset <Grammema> [pairs.Count]; int j = 0; foreach (var pair in pairs) { grammems[j] = Grammema.CreateGrammema(builder, pair.Key, pair.Value); j++; } var gramsCol = Lexema.CreateGrammemsVector(builder, grammems); words[i] = Lexema.CreateLexema(builder, i, EntryName, word.ID_Entry, word.ID_PartOfSpeech, gramsCol, 0, RealWord, word.rcind); } var wordsCol = Sentence.CreateWordsVector(builder, words); // Чтение узлов var treelist = sentence.GetTreeList(); var nodes = new Offset <Node> [treelist.Count]; for (int i = 0; i < treelist.Count; i++) { nodes[i] = Node.CreateNode(builder, treelist[i].ID, treelist[i].Level, treelist[i].index, treelist[i].linktype, treelist[i].parentind); } var nodesCol = Sentence.CreateNodesVector(builder, nodes); var sentVal = builder.CreateString(""); return(Sentence.CreateSentence(builder, order, nodesCol, wordsCol, sentVal)); }