Esempio n. 1
0
        public async void Annotate(ITextSelection selectedTxt, Dimension selectedDim)
        {
            if (selectedTxt != null && selectedDim != null)
            {
                //check if exist in list exact anno
                List <SysAnnotation> currentAnno = CurrentSentence.ActiveSysSentence.Annotations.
                                                   Where(p => p.StartPosition == selectedTxt.StartPosition && p.EndPosition == selectedTxt.EndPosition).ToList();

                if (currentAnno.Any()) // exatc anno exist - edit it
                {
                    int editIndex = CurrentSentence.ActiveSysSentence.Annotations.IndexOf(currentAnno.ElementAt(0));
                    CurrentSentence.ActiveSysSentence.Annotations.ElementAt(editIndex).AnnoDim = selectedDim;
                    sentenceService.ApplyVisualChangeAnno(selectedTxt, selectedDim.Color);
                }
                else
                {
                    // is it overlay or doesn't exist

                    if (sentenceService.CheckIfAnnoOverlay(CurrentSentence.ActiveSysSentence.Annotations, selectedTxt))
                    {
                        // anno overlays - do not create new anno or edit old
                        await new Windows.UI.Popups.MessageDialog("Can't add an annotation over existing one - overlay.").ShowAsync();
                    }
                    else if (selectedTxt.StartPosition == selectedTxt.EndPosition) // start == end
                    {
                        await new Windows.UI.Popups.MessageDialog("Can't add an annotation! Please select at least one word.").ShowAsync();
                    }
                    else // anno doesn't exist - add it
                    {
                        SysAnnotation newAnno = new SysAnnotation()
                        {
                            AnnoDim       = selectedDim,
                            StartPosition = selectedTxt.StartPosition,
                            EndPosition   = selectedTxt.EndPosition
                        };

                        CurrentSentence.ActiveSysSentence.Annotations.Add(newAnno);
                        sentenceService.ApplyVisualChangeAnno(selectedTxt, selectedDim.Color);
                    }
                }
            }
        }
Esempio n. 2
0
        public Corpus LoadCorpusFromFile(IList <string> lines)
        {
            Corpus myCorpus = new Corpus();

            int index = 0;

            for (int i = 0; i < lines.Count(); i = i + 6)
            {
                string src = lines[i].Trim().Substring(5);
                myCorpus.SourceSentences.Add(new Sentence()
                {
                    Index = index, Text = src
                });

                string refLine = "";
                if (lines[i + 1].Length > 5)
                {
                    refLine = lines[i + 1].Trim().Substring(5);
                }
                myCorpus.ReferenceSentences.Add(new Sentence()
                {
                    Index = index, Text = refLine
                });

                string sys = lines[i + 2].Trim().Substring(5);
                myCorpus.SystemSentences.Add(new SysSentence()
                {
                    Index = index, Text = sys
                });

                string sysAnno = "";
                if (lines[i + 3].Length > 9)
                {
                    sysAnno = lines[i + 3].Trim().Substring(9);
                    string[]      listOfAnno = sysAnno.Split(' '); //   XXX*XXX*STRING
                    List <string> rez        = new List <string>();
                    Regex         regex      = new Regex("(?<=#).*?(?=#)");

                    foreach (var item in listOfAnno)
                    {
                        foreach (Match match in regex.Matches(item))
                        {
                            rez.Add(match.Value);
                        }
                    }

                    for (int j = 0; j < rez.Count(); j = j + 3)
                    {
                        Dimension foundDim = new Dimension();
                        var       dimList  = App.typologyApp.Dimensions.Where(d => d.Id == rez[j + 2]).ToList();
                        if (dimList.Any())
                        {
                            foundDim = dimList.ElementAt(0);
                        }
                        else
                        {
                            return(null);
                        }

                        SysAnnotation newAnno = new SysAnnotation()
                        {
                            StartPosition = Int32.Parse(rez[j]),
                            EndPosition   = Int32.Parse(rez[j + 1]),
                            AnnoDim       = foundDim
                        };

                        myCorpus.SystemSentences.ElementAt(index).Annotations.Add(newAnno);
                    }
                }

                string sysModify = "";
                if (lines[i + 4].Length > 11)
                {
                    sysModify = lines[i + 4].Trim().Substring(11);
                }
                myCorpus.ModifiedSystemSentences.Add(new Sentence()
                {
                    Index = index, Text = sysModify
                });

                long   time    = 0;
                string timeStr = "";
                if (lines[i + 5].Length > 13)
                {
                    timeStr = lines[i + 5].Trim().Substring(13);
                    time    = long.Parse(timeStr);
                }
                myCorpus.TimeOfEditSen.Add(time);
                index++;
            }
            // build model
            return(myCorpus);
        }