Inheritance: ObservableObject
Exemple #1
0
 public SoundContext ToSoundContext(CogProject project, SegmentPool segmentPool)
 {
     IWordAligner aligner = project.WordAligners[ComponentIdentifiers.PrimaryWordAligner];
     SoundClass leftEnv = LeftEnvironment == null ? null : aligner.ContextualSoundClasses.First(sc => sc.Name == LeftEnvironment);
     SoundClass rightEnv = RightEnvironment == null ? null : aligner.ContextualSoundClasses.First(sc => sc.Name == RightEnvironment);
     return new SoundContext(leftEnv, new Ngram<Segment>(_target.Select(segmentPool.GetExisting)), rightEnv);
 }
        public void Meanings()
        {
            DispatcherHelper.Initialize();
            var projectService = Substitute.For<IProjectService>();
            var busyService = Substitute.For<IBusyService>();
            var exportService = Substitute.For<IExportService>();
            var analysisService = Substitute.For<IAnalysisService>();

            var alignment = new MultipleWordAlignmentViewModel(projectService, busyService, exportService, analysisService);

            var project = new CogProject(_spanFactory)
                {
                    Meanings = {new Meaning("gloss2", "cat2"), new Meaning("gloss1", "cat1"), new Meaning("gloss3", "cat3")}
                };

            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            Assert.That(alignment.SelectedMeaning, Is.Null);
            alignment.MeaningsView = new ListCollectionView(alignment.Meanings);

            Assert.That(alignment.SelectedMeaning.Gloss, Is.EqualTo("gloss1"));
            Assert.That(alignment.MeaningsView.Cast<MeaningViewModel>().Select(s => s.Gloss), Is.EqualTo(new[] {"gloss1", "gloss2", "gloss3"}));

            project.Meanings.Insert(0, new Meaning("gloss4", "cat4"));
            Assert.That(alignment.MeaningsView.Cast<MeaningViewModel>().Select(s => s.Gloss), Is.EqualTo(new[] {"gloss1", "gloss2", "gloss3", "gloss4"}));
        }
        public void Import(object importSettingsViewModel, Stream stream, CogProject project)
        {
            XDocument doc;
            if (ZipFile.IsZipFile(stream, false))
            {
                stream.Seek(0, SeekOrigin.Begin);
                ZipFile zipFile = ZipFile.Read(stream);
                ZipEntry kmlEntry = zipFile.First(entry => entry.FileName.EndsWith(".kml"));
                doc = XDocument.Load(kmlEntry.OpenReader(), LoadOptions.SetLineInfo);
            }
            else
            {
                doc = XDocument.Load(stream, LoadOptions.SetLineInfo);
            }
            XElement root = doc.Root;
            Debug.Assert(root != null);

            if (root.GetDefaultNamespace() != DefaultNamespace)
                throw new ImportException("The specified file is not a KML file.");

            XElement document = root.Element(Kml + "Document");
            if (document == null)
                throw new ImportException("Missing Document element.");

            var regions = new Dictionary<Variety, List<GeographicRegion>>();
            LoadFolder(project, regions, document);

            foreach (KeyValuePair<Variety, List<GeographicRegion>> varietyRegions in regions)
                varietyRegions.Key.Regions.AddRange(varietyRegions.Value);
        }
Exemple #4
0
        private bool HasSonorityScaleChanged(CogProject project, SonorityClass[] scale)
        {
            SonorityClass[] origSonorityScale = {
                    new SonorityClass(1, new NaturalClass("Stop", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.ConsonantType).Symbol("stop").Symbol("nasal-").Value)),
                    new SonorityClass(2, new NaturalClass("Affricate", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.ConsonantType).Symbol("affricate").Value)),
                    new SonorityClass(3, new NaturalClass("Fricative", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.ConsonantType).Symbol("fricative").Symbol("lateral-").Value)),
                    new SonorityClass(4, new NaturalClass("Nasal", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.ConsonantType).Symbol("nasal+").Value)),
                    new SonorityClass(5, new NaturalClass("Trill", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.ConsonantType).Symbol("trill").Value)),
                    new SonorityClass(6, new NaturalClass("Lateral", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.ConsonantType).Symbol("lateral+").Value)),
                    new SonorityClass(7, new NaturalClass("Flap", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.ConsonantType).Symbol("flap").Value)),
                    new SonorityClass(8, new UnnaturalClass("Glide", new[] {"j", "ɥ", "ɰ", "w"}, false, project.Segmenter)),
                    new SonorityClass(8, new NaturalClass("Non-syllabic vowel", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic-").Value)),
                    new SonorityClass(9, new NaturalClass("Close vowel", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic+").Symbol("close").Value)),
                    new SonorityClass(10, new NaturalClass("Near-close vowel", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic+").Symbol("near-close").Value)),
                    new SonorityClass(11, new NaturalClass("Close-mid vowel", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic+").Symbol("close-mid").Value)),
                    new SonorityClass(12, new NaturalClass("Mid vowel", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic+").Symbol("mid").Value)),
                    new SonorityClass(13, new NaturalClass("Open-mid vowel", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic+").Symbol("open-mid").Value)),
                    new SonorityClass(14, new NaturalClass("Near-open vowel", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic+").Symbol("near-open").Value)),
                    new SonorityClass(15, new NaturalClass("Open vowel", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic+").Symbol("open-vowel").Value))
                };

            if (origSonorityScale.Length != scale.Length)
                return true;

            for (int i = 0; i < origSonorityScale.Length; i++)
            {
                SonorityClass origClass = origSonorityScale[i];
                SonorityClass curClass = scale[i];
                if (origClass.Sonority != curClass.Sonority || origClass.SoundClass.Name != curClass.SoundClass.Name)
                    return true;

                var origNC = origClass.SoundClass as NaturalClass;
                if (origNC != null)
                {
                    var curNC = curClass.SoundClass as NaturalClass;
                    if (curNC == null)
                        return true;
                    FeatureStruct origFS1 = origNC.FeatureStruct;
                    FeatureStruct origFS2 = null;
                    // the original open vowel class can have the height set to open or the manner set to open-vowel
                    if (origNC.Name == "Open vowel")
                        origFS2 = FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic+").Symbol("open").Value;
                    if (!origFS1.ValueEquals(curNC.FeatureStruct) && (origFS2 == null || !origFS2.ValueEquals(curNC.FeatureStruct)))
                        return true;
                }
                else
                {
                    var origUC = (UnnaturalClass) origClass.SoundClass;
                    var curUC = curClass.SoundClass as UnnaturalClass;
                    if (curUC == null || !origUC.Segments.SequenceEqual(curUC.Segments))
                        return true;
                }
            }
            return false;
        }
Exemple #5
0
 // We may not ever use this function; if so, we can delete it later.
 public void CheckIsDefaultProject(CogProject project)
 {
     Assert.That(project, Is.Not.Null);
     Assert.That(project.Varieties, Is.Empty);
     Assert.That(project.FeatureSystem, Is.Not.Empty);
     Assert.That(project.FeatureSystem.Count, Is.EqualTo(17));
     Assert.That(project.FeatureSystem.Select(feat => feat.ToString()).Take(5), Is.EquivalentTo(new string[] { "Place", "Manner", "Syllabic", "Voice", "Nasal" }));
     IEnumerable<string> consonantSample = project.Segmenter.Consonants.Select(symbol => symbol.StrRep).Skip(20).Take(20);
     string joinedSample = string.Join("", consonantSample);
     Assert.That(joinedSample, Is.EqualTo("zçðħŋᵑɓɕɖɗɟɠɡɢɣɥɦɧɫɬ"));
 }
Exemple #6
0
        public void Migrate(SegmentPool segmentPool, CogProject project)
        {
            if (project.FeatureSystem.ContainsFeature("airstream"))
                return;

            var pulmonic = new FeatureSymbol("pulmonic");
            var ejective = new FeatureSymbol("ejective");
            var implosive = new FeatureSymbol("implosive");
            var click = new FeatureSymbol("click");
            var airstream = new SymbolicFeature("airstream",
                pulmonic,
                ejective,
                implosive,
                click) {Description = "Airstream"};
            project.FeatureSystem.Add(airstream);

            AddValue(project.Segmenter.Modifiers, "ʼ", ejective);

            AddValue(project.Segmenter.Consonants, "ɓ", implosive);
            AddValue(project.Segmenter.Consonants, "ɗ", implosive);
            AddValue(project.Segmenter.Consonants, "ʄ", implosive);
            AddValue(project.Segmenter.Consonants, "ɠ", implosive);
            AddValue(project.Segmenter.Consonants, "ʛ", implosive);

            FeatureSymbol affricate;
            if (project.FeatureSystem.TryGetSymbol("affricate", out affricate))
            {
                project.Segmenter.Consonants.AddSymbolBasedOn("ʘ", "p", affricate, click);
                project.Segmenter.Consonants.AddSymbolBasedOn("ǀ", "θ", affricate, click);
                project.Segmenter.Consonants.AddSymbolBasedOn("ǁ", "ɬ", affricate, click);
            }
            project.Segmenter.Consonants.AddSymbolBasedOn("ǃ", "t", click);
            project.Segmenter.Consonants.AddSymbolBasedOn("ǂ", "c", click);

            foreach (Symbol symbol in project.Segmenter.Vowels.ToArray())
                AddValue(project.Segmenter.Vowels, symbol, pulmonic);

            foreach (Symbol symbol in project.Segmenter.Consonants.Where(s => !s.FeatureStruct.ContainsFeature("airstream")).ToArray())
                AddValue(project.Segmenter.Consonants, symbol, pulmonic);

            foreach (KeyValuePair<string, IWordAligner> aligner in project.WordAligners.Where(kvp => kvp.Value is Aline).ToArray())
            {
                var aline = (Aline) aligner.Value;
                Dictionary<SymbolicFeature, int> featWeights = aline.FeatureWeights.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                featWeights[airstream] = 5;
                Dictionary<FeatureSymbol, int> valueMetrics = aline.ValueMetrics.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                valueMetrics[pulmonic] = 100;
                valueMetrics[ejective] = 66;
                valueMetrics[implosive] = 33;
                valueMetrics[click] = 0;
                project.WordAligners[aligner.Key] = new Aline(segmentPool, aline.RelevantVowelFeatures, aline.RelevantConsonantFeatures.Concat(airstream),
                    featWeights, valueMetrics, aline.Settings);
            }
        }
Exemple #7
0
        public void Migrate(SegmentPool segmentPool, CogProject project)
        {
            AddToneNumber(project, "¹");
            AddToneNumber(project, "²");
            AddToneNumber(project, "³");
            AddToneNumber(project, "⁴");
            AddToneNumber(project, "⁵");

            FeatureSymbol alvPal;
            if (project.FeatureSystem.TryGetSymbol("alveolo-palatal", out alvPal))
            {
                project.Segmenter.Consonants.AddSymbolBasedOn("ȶ", "t", alvPal);
                project.Segmenter.Consonants.AddSymbolBasedOn("ȡ", "d", alvPal);
                project.Segmenter.Consonants.AddSymbolBasedOn("ȵ", "n", alvPal);
                project.Segmenter.Consonants.AddSymbolBasedOn("ȴ", "l", alvPal);
            }
        }
        private CogProject CreateProject()
        {
            var project = new CogProject(_spanFactory);
            var variety1 = new Variety("variety1");
            project.Varieties.Add(variety1);
            var variety2 = new Variety("variety2");
            project.Varieties.Add(variety2);
            var variety3 = new Variety("variety3");
            project.Varieties.Add(variety3);
            var meaning1 = new Meaning("meaning1", null);
            project.Meanings.Add(meaning1);
            var meaning2 = new Meaning("meaning2", null);
            project.Meanings.Add(meaning2);
            var meaning3 = new Meaning("meaning3", null);
            project.Meanings.Add(meaning3);

            variety1.Words.Add(new Word("word1", meaning1));
            variety1.Words.Add(new Word("word2", meaning2));
            variety1.Words.Add(new Word("word3", meaning3));

            variety2.Words.Add(new Word("word4", meaning1));
            variety2.Words.Add(new Word("word5", meaning2));
            variety2.Words.Add(new Word("word6", meaning3));

            variety3.Words.Add(new Word("word7", meaning1));
            variety3.Words.Add(new Word("word8", meaning2));
            variety3.Words.Add(new Word("word9", meaning3));

            var vpGenerator = new VarietyPairGenerator();
            vpGenerator.Process(project);

            double score = 1.0;
            foreach (VarietyPair vp in project.VarietyPairs)
            {
                foreach (Meaning meaning in project.Meanings)
                {
                    Word w1 = vp.Variety1.Words[meaning].First();
                    Word w2 = vp.Variety2.Words[meaning].First();
                    WordPair wp = vp.WordPairs.Add(w1, w2);
                    wp.PredictedCognacyScore = score;
                    wp.PredictedCognacy = true;
                    score -= 0.1;
                }
            }
            return project;
        }
        public void Import(object importSettingsViewModel, Stream stream, CogProject project)
        {
            var reader = new CsvReader(new StreamReader(stream), ',');
            if (!SkipRows(reader, 5))
            {
                project.Meanings.Clear();
                project.Varieties.Clear();
                return;
            }

            var varieties = new List<Variety>();
            var meanings = new Dictionary<string, Meaning>();
            IList<string> varietyRow;
            while (reader.ReadRow(out varietyRow))
            {
                if (string.IsNullOrEmpty(varietyRow[0]))
                    break;

                var variety = new Variety(varietyRow[0].Trim());
                if (!SkipRows(reader, 2))
                    throw new ImportException("Metadata for a variety is incomplete.");

                Meaning curMeaning = null;
                IList<string> glossRow;
                while (reader.ReadRow(out glossRow) && glossRow.Any(s => !string.IsNullOrEmpty(s)))
                {
                    if (!string.IsNullOrEmpty(glossRow[0]))
                    {
                        string gloss = glossRow[0].Trim();
                        curMeaning = meanings.GetValue(gloss, () => new Meaning(gloss, null));
                    }
                    if (curMeaning == null)
                        throw new ImportException("A gloss is missing.");

                    string wordStr = glossRow[1].Trim();
                    if (!string.IsNullOrEmpty(wordStr))
                        variety.Words.Add(new Word(wordStr, curMeaning));
                }
                varieties.Add(variety);
            }

            project.Meanings.ReplaceAll(meanings.Values);
            project.Varieties.ReplaceAll(varieties);
        }
        public void Export(Stream stream, CogProject project, SimilarityMetric similarityMetric)
        {
            var optics = new Optics<Variety>(variety => variety.VarietyPairs.Select(pair =>
                {
                    double score = 0;
                    switch (similarityMetric)
                    {
                        case SimilarityMetric.Lexical:
                            score = pair.LexicalSimilarityScore;
                            break;
                        case SimilarityMetric.Phonetic:
                            score = pair.PhoneticSimilarityScore;
                            break;
                    }
                    return Tuple.Create(pair.GetOtherVariety(variety), 1.0 - score);
                }).Concat(Tuple.Create(variety, 0.0)), 2);

            Variety[] varietyArray = optics.ClusterOrder(project.Varieties).Select(oe => oe.DataObject).ToArray();
            using (var writer = new StreamWriter(new NonClosingStreamWrapper(stream)))
            {
                foreach (Variety variety in varietyArray)
                {
                    writer.Write("\t");
                    writer.Write(variety.Name);
                }
                writer.WriteLine();
                for (int i = 0; i < varietyArray.Length; i++)
                {
                    writer.Write(varietyArray[i].Name);
                    for (int j = 0; j < varietyArray.Length; j++)
                    {
                        writer.Write("\t");
                        if (i != j)
                        {
                            VarietyPair varietyPair = varietyArray[i].VarietyPairs[varietyArray[j]];
                            double score = similarityMetric == SimilarityMetric.Lexical ? varietyPair.LexicalSimilarityScore : varietyPair.PhoneticSimilarityScore;
                            writer.Write("{0:0.00}", score);
                        }
                    }
                    writer.WriteLine();
                }
            }
        }
Exemple #11
0
        public void Export(Stream stream, CogProject project)
        {
            using (var writer = new StreamWriter(new NonClosingStreamWrapper(stream)))
            {
                var meaningClusters = new Dictionary<Meaning, List<Cluster<Word>>>();
                foreach (Meaning meaning in project.Meanings)
                {
                    writer.Write("\t");
                    writer.Write(meaning.Gloss);
                    meaningClusters[meaning] = project.GenerateCognateSets(meaning).OrderBy(c => c.Noise).ThenByDescending(c => c.DataObjects.Count).ToList();

                }
                writer.WriteLine();
                foreach (Meaning meaning in project.Meanings)
                {
                    writer.Write("\t");
                    writer.Write(meaning.Category);
                }
                writer.WriteLine();

                foreach (Variety variety in project.Varieties)
                {
                    writer.Write(variety.Name);
                    foreach (Meaning meaning in project.Meanings)
                    {
                        writer.Write("\t");
                        bool first = true;
                        foreach (Word word in variety.Words[meaning])
                        {
                            if (!first)
                                writer.Write(',');
                            int i = meaningClusters[meaning].FindIndex(set => set.DataObjects.Contains(word));
                            if (i == -1 || i == meaningClusters[meaning].Count - 1)
                                writer.Write("X");
                            else
                                writer.Write(i + 1);
                            first = false;
                        }
                    }
                    writer.WriteLine();
                }
            }
        }
        public void Export(Stream stream, CogProject project, SyllablePosition syllablePosition)
        {
            FeatureSymbol domainSyllablePosition = null;
            switch (syllablePosition)
            {
                case SyllablePosition.Onset:
                    domainSyllablePosition = CogFeatureSystem.Onset;
                    break;
                case SyllablePosition.Nucleus:
                    domainSyllablePosition = CogFeatureSystem.Nucleus;
                    break;
                case SyllablePosition.Coda:
                    domainSyllablePosition = CogFeatureSystem.Coda;
                    break;
            }

            var comparer = new SegmentComparer();
            Segment[] segments = project.Varieties
                .SelectMany(v => v.SyllablePositionSegmentFrequencyDistributions[domainSyllablePosition].ObservedSamples)
                .Distinct().OrderBy(GetSortOrder).ThenBy(s => s, comparer).ToArray();

            using (var writer = new StreamWriter(new NonClosingStreamWrapper(stream)))
            {
                foreach (Segment seg in segments)
                {
                    writer.Write("\t");
                    writer.Write(seg.StrRep);
                }
                writer.WriteLine();

                foreach (Variety variety in project.Varieties)
                {
                    writer.Write(variety.Name);
                    foreach (Segment seg in segments)
                    {
                        writer.Write("\t");
                        writer.Write(variety.SyllablePositionSegmentFrequencyDistributions[domainSyllablePosition][seg]);
                    }
                    writer.WriteLine();
                }
            }
        }
        public void TaskAreas_EditMeaning_MeaningUpdated()
        {
            using (var env = new TestEnvironment())
            {
                var project = new CogProject(env.SpanFactory)
                {
                    Meanings = {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2")}
                };
                env.OpenProject(project);

                var commonTasks = (TaskAreaItemsViewModel) env.MeaningsViewModel.TaskAreas[0];
                var renameVariety = (TaskAreaCommandViewModel) commonTasks.Items[1];
                env.MeaningsViewModel.SelectedMeaning = env.MeaningsViewModel.Meanings.First(v => v.Gloss == "gloss2");
                env.DialogService.ShowModalDialog(env.MeaningsViewModel, Arg.Do<EditMeaningViewModel>(vm => vm.Gloss = "gloss3")).Returns(true);
                renameVariety.Command.Execute(null);
                Assert.That(env.MeaningsViewModel.SelectedMeaning.Gloss, Is.EqualTo("gloss3"));
                Assert.That(env.MeaningsViewModel.Meanings.Select(v => v.Gloss), Is.EqualTo(new[] {"gloss1", "gloss3"}));
                Assert.That(project.Meanings.Contains("gloss2"), Is.False);
            }
        }
 public void Export_EmptyProject()
 {
     var project = new CogProject(_spanFactory);
     var exporter = new NexusSimilarityMatrixExporter();
     using (var stream = new MemoryStream())
     {
         exporter.Export(stream, project, SimilarityMetric.Lexical);
         Assert.That(Encoding.UTF8.GetString(stream.ToArray()), Is.EqualTo(@"#NEXUS
     BEGIN Taxa;
     DIMENSIONS NTax=0;
     TAXLABELS;
     END;
     BEGIN Distances;
     DIMENSIONS NTax=0;
     FORMAT Triangle=LOWER Diagonal Labels Missing=?;
     MATRIX;
     END;
     "));
     }
 }
 public void Export_EmptyProject()
 {
     var project = new CogProject(_spanFactory);
     var exporter = new NexusCognateSetsExporter();
     using (var stream = new MemoryStream())
     {
         exporter.Export(stream, project);
         Assert.That(Encoding.UTF8.GetString(stream.ToArray()), Is.EqualTo(@"#NEXUS
     BEGIN Taxa;
     DIMENSIONS NTax=0;
     TAXLABELS;
     END;
     BEGIN Characters;
     DIMENSIONS NChar=0;
     FORMAT Datatype=STANDARD Missing=? Symbols=""0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"";
     MATRIX;
     END;
     "));
     }
 }
Exemple #16
0
        public void Migrate(SegmentPool segmentPool, CogProject project)
        {
            // add prenasal superscript for n
            project.Segmenter.Consonants.AddSymbolBasedOn("ⁿ", "n");

            foreach (KeyValuePair<string, IProcessor<Variety>> kvp in project.VarietyProcessors.Where(kvp => kvp.Value is SspSyllabifier).ToArray())
            {
                var syllabifier = (SspSyllabifier) kvp.Value;
                SonorityClass[] scale = syllabifier.SonorityScale.OrderBy(sc => sc.Sonority).ThenBy(sc => sc.SoundClass.Name).ToArray();
                // if the user has changed the sonority scale preserve their changes and do not update
                if (HasSonorityScaleChanged(project, scale))
                    continue;

                // add prenasal sonority class
                var newScale = new List<SonorityClass> {new SonorityClass(1, new UnnaturalClass("Prenasal", new[] {"ᵐ", "ⁿ", "ᵑ"}, false, project.Segmenter))};
                foreach (SonorityClass sc in scale)
                {
                    SoundClass newClass;
                    switch (sc.SoundClass.Name)
                    {
                        case "Glide":
                            // correct the ignore modifiers flag on the "Glide" class
                            newClass = new UnnaturalClass("Glide", new[] {"j", "ɥ", "ɰ", "w"}, true, project.Segmenter);
                            break;
                        case "Open vowel":
                            // correct the height feature value on the "Open vowel" class
                            newClass = new NaturalClass("Open vowel", FeatureStruct.New(project.FeatureSystem).Symbol(CogFeatureSystem.VowelType).Symbol("syllabic+").Symbol("open").Value);
                            break;
                        default:
                            newClass = sc.SoundClass;
                            break;
                    }
                    // increment sonority for all existing classes
                    newScale.Add(new SonorityClass(sc.Sonority + 1, newClass));
                }
                project.VarietyProcessors[kvp.Key] = new SspSyllabifier(syllabifier.CombineVowels, syllabifier.CombineConsonants, syllabifier.VowelsSameSonorityTautosyllabic,
                    segmentPool, newScale);
            }
        }
Exemple #17
0
 public void SetUp()
 {
     _featSys = new FeatureSystem
         {
             new SymbolicFeature("place",
                 new FeatureSymbol("bilabial"),
                 new FeatureSymbol("labiodental"),
                 new FeatureSymbol("dental"),
                 new FeatureSymbol("alveolar"),
                 new FeatureSymbol("retroflex"),
                 new FeatureSymbol("palato-alveolar"),
                 new FeatureSymbol("alveolo-palatal"),
                 new FeatureSymbol("palatal"),
                 new FeatureSymbol("velar"),
                 new FeatureSymbol("uvular"),
                 new FeatureSymbol("pharyngeal"),
                 new FeatureSymbol("epiglottal"),
                 new FeatureSymbol("glottal"))
         };
     _project = new CogProject(_spanFactory) {FeatureSystem = _featSys};
     _segmentPool = new SegmentPool();
 }
        private void LoadFolder(CogProject project, Dictionary<Variety, List<GeographicRegion>> regions, XElement elem)
        {
            foreach (XElement placemark in elem.Elements(Kml + "Placemark"))
            {
                var name = (string) placemark.Element(Kml + "name");
                Variety variety;
                if (!string.IsNullOrEmpty(name) && project.Varieties.TryGetValue(name, out variety))
                {
                    XElement polygon = placemark.Element(Kml + "Polygon");
                    if (polygon != null)
                        regions.GetValue(variety, () => new List<GeographicRegion>()).Add(LoadRegion(polygon, (string) placemark.Element(Kml + "description")));
                }
            }

            foreach (XElement folder in elem.Elements(Kml + "Folder"))
            {
                var name = (string) folder.Element(Kml + "name");
                Variety variety;
                if (!string.IsNullOrEmpty(name) && project.Varieties.TryGetValue(name, out variety))
                    LoadVarietyFolder(regions, variety, folder);
                else
                    LoadFolder(project, regions, folder);
            }
        }
Exemple #19
0
        public void FindCommand()
        {
            DispatcherHelper.Initialize();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var analysisService = Substitute.For<IAnalysisService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);
            VarietiesVarietyViewModel.Factory varietyFactory = variety => new VarietiesVarietyViewModel(projectService, dialogService, wordsFactory, wordFactory, variety);

            var varieties = new VarietiesViewModel(projectService, dialogService, analysisService, varietyFactory);

            var project = new CogProject(_spanFactory)
                {
                    Meanings = {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")},
                    Varieties = {new Variety("variety1"), new Variety("variety2")}
                };
            project.Varieties[0].Words.AddRange(new[] {new Word("hello", project.Meanings[0]), new Word("good", project.Meanings[1]), new Word("bad", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("help", project.Meanings[0]), new Word("google", project.Meanings[1]), new Word("goofy", project.Meanings[2])});
            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            varieties.VarietiesView = new ListCollectionView(varieties.Varieties);
            WordsViewModel wordsViewModel = varieties.SelectedVariety.Words;
            wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words);
            WordViewModel[] wordsViewArray = wordsViewModel.WordsView.Cast<WordViewModel>().ToArray();

            FindViewModel findViewModel = null;
            Action closeCallback = null;
            dialogService.ShowModelessDialog(varieties, Arg.Do<FindViewModel>(vm => findViewModel = vm), Arg.Do<Action>(callback => closeCallback = callback));
            varieties.FindCommand.Execute(null);
            Assert.That(findViewModel, Is.Not.Null);
            Assert.That(closeCallback, Is.Not.Null);

            // already open, shouldn't get opened twice
            dialogService.ClearReceivedCalls();
            varieties.FindCommand.Execute(null);
            dialogService.DidNotReceive().ShowModelessDialog(varieties, Arg.Any<FindViewModel>(), Arg.Any<Action>());

            // form searches
            findViewModel.Field = FindField.Form;

            // nothing selected, no match
            findViewModel.String = "fall";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.Empty);

            // nothing selected, matches
            findViewModel.String = "he";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable()));

            // first word selected, matches
            findViewModel.String = "o";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable()));
            // start search over
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));

            // last word selected, matches
            wordsViewModel.SelectedWords.Clear();
            wordsViewModel.SelectedWords.Add(wordsViewArray[2]);
            findViewModel.String = "ba";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable()));

            // switch variety, nothing selected, matches, change selected word
            varieties.SelectedVariety = varieties.Varieties[1];
            wordsViewModel = varieties.SelectedVariety.Words;
            wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words);
            wordsViewArray = wordsViewModel.WordsView.Cast<WordViewModel>().ToArray();
            findViewModel.String = "go";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            wordsViewModel.SelectedWords.Clear();
            wordsViewModel.SelectedWords.Add(wordsViewArray[0]);
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable()));

            // gloss searches
            findViewModel.Field = FindField.Gloss;
            findViewModel.String = "gloss2";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
        }
Exemple #20
0
        public void Varieties()
        {
            DispatcherHelper.Initialize();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var analysisService = Substitute.For<IAnalysisService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);
            VarietiesVarietyViewModel.Factory varietyFactory = variety => new VarietiesVarietyViewModel(projectService, dialogService, wordsFactory, wordFactory, variety);

            var varieties = new VarietiesViewModel(projectService, dialogService, analysisService, varietyFactory);

            var project = new CogProject(_spanFactory);
            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            varieties.VarietiesView = new ListCollectionView(varieties.Varieties);

            Assert.That(varieties.Varieties, Is.Empty);
            Assert.That(varieties.IsVarietySelected, Is.False);
            Assert.That(varieties.SelectedVariety, Is.Null);

            project.Varieties.Add(new Variety("variety1"));

            Assert.That(varieties.Varieties.Count, Is.EqualTo(1));
            Assert.That(varieties.Varieties[0].Name, Is.EqualTo("variety1"));
            Assert.That(varieties.IsVarietySelected, Is.True);
            Assert.That(varieties.SelectedVariety, Is.EqualTo(varieties.VarietiesView.Cast<VarietiesVarietyViewModel>().First()));

            project = new CogProject(_spanFactory)
                {
                    Varieties = {new Variety("French"), new Variety("English"), new Variety("Spanish")}
                };
            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] {"French", "English", "Spanish"}));
            Assert.That(varieties.IsVarietySelected, Is.False);
            Assert.That(varieties.SelectedVariety, Is.Null);

            varieties.VarietiesView = new ListCollectionView(varieties.Varieties);
            VarietiesVarietyViewModel[] varietiesViewArray = varieties.VarietiesView.Cast<VarietiesVarietyViewModel>().ToArray();
            Assert.That(varieties.IsVarietySelected, Is.True);
            Assert.That(varieties.SelectedVariety, Is.EqualTo(varietiesViewArray[0]));
            // should be sorted
            Assert.That(varietiesViewArray.Select(v => v.Name), Is.EqualTo(new[] {"English", "French", "Spanish"}));
        }
Exemple #21
0
        public void TaskAreas()
        {
            DispatcherHelper.Initialize();
            var projectService = Substitute.For<IProjectService>();
            var dialogService = Substitute.For<IDialogService>();
            var busyService = Substitute.For<IBusyService>();
            var analysisService = Substitute.For<IAnalysisService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);
            VarietiesVarietyViewModel.Factory varietyFactory = variety => new VarietiesVarietyViewModel(projectService, dialogService, wordsFactory, wordFactory, variety);

            var varieties = new VarietiesViewModel(projectService, dialogService, analysisService, varietyFactory);

            var project = new CogProject(_spanFactory)
                {
                    Meanings = {new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3")},
                    Varieties = {new Variety("variety1"), new Variety("variety2")}
                };
            project.Varieties[0].Words.AddRange(new[] {new Word("hello", project.Meanings[0]), new Word("good", project.Meanings[1]), new Word("bad", project.Meanings[2])});
            project.Varieties[1].Words.AddRange(new[] {new Word("help", project.Meanings[0]), new Word("google", project.Meanings[1]), new Word("goofy", project.Meanings[2])});
            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            varieties.VarietiesView = new ListCollectionView(varieties.Varieties);

            var commonTasks = (TaskAreaItemsViewModel) varieties.TaskAreas[0];

            var addVariety = (TaskAreaCommandViewModel) commonTasks.Items[0];
            dialogService.ShowModalDialog(varieties, Arg.Do<EditVarietyViewModel>(vm => vm.Name = "variety3")).Returns(true);
            addVariety.Command.Execute(null);
            Assert.That(varieties.SelectedVariety.Name, Is.EqualTo("variety3"));
            Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] {"variety1", "variety2", "variety3"}));

            var renameVariety = (TaskAreaCommandViewModel) commonTasks.Items[1];
            dialogService.ShowModalDialog(varieties, Arg.Do<EditVarietyViewModel>(vm => vm.Name = "variety4")).Returns(true);
            renameVariety.Command.Execute(null);
            Assert.That(varieties.SelectedVariety.Name, Is.EqualTo("variety4"));
            Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] {"variety1", "variety2", "variety4"}));

            var removeVariety = (TaskAreaCommandViewModel) commonTasks.Items[2];
            dialogService.ShowYesNoQuestion(varieties, Arg.Any<string>(), Arg.Any<string>()).Returns(true);
            removeVariety.Command.Execute(null);
            Assert.That(varieties.SelectedVariety.Name, Is.EqualTo("variety1"));
            Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] {"variety1", "variety2"}));

            varieties.SelectedVariety = varieties.Varieties.First(v => v.Name == "variety2");

            WordsViewModel wordsViewModel = varieties.SelectedVariety.Words;
            wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words);
            var sortWordsByItems = (TaskAreaItemsViewModel) commonTasks.Items[4];
            var sortWordsByGroup = (TaskAreaCommandGroupViewModel) sortWordsByItems.Items[0];
            // default sorting is by gloss, change to form
            sortWordsByGroup.SelectedCommand = sortWordsByGroup.Commands[1];
            sortWordsByGroup.SelectedCommand.Command.Execute(null);
            Assert.That(wordsViewModel.WordsView.Cast<WordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] {"goofy", "google", "help"}));
            // change sorting back to gloss
            sortWordsByGroup.SelectedCommand = sortWordsByGroup.Commands[0];
            sortWordsByGroup.SelectedCommand.Command.Execute(null);
            Assert.That(wordsViewModel.WordsView.Cast<WordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] {"help", "google", "goofy"}));
        }
Exemple #22
0
        private void SetupProject(ProgressViewModel vm, string path, string name, CogProject project)
        {
            _settingsService.LastProject = path;
            if (MigrateProjectIfNeeded(vm, project))
                _isChanged = true;
            _project = project;
            _projectName = name;

            if (vm != null)
                vm.Text = "Segmenting and syllabifying words...";
            _analysisService.Value.SegmentAll();

            if (path != null)
            {
                string cacheFileName = Path.Combine(Path.GetTempPath(), Path.GetFileName(path) + ".cache");
                if (File.Exists(cacheFileName))
                {
                    if (vm != null)
                        vm.Text = "Loading cached results...";
                    bool delete = true;
                    if (!_isChanged)
                    {
                        try
                        {
                            using (FileStream fs = File.OpenRead(cacheFileName))
                            {
                                var version = Serializer.DeserializeWithLengthPrefix<int>(fs, PrefixStyle.Base128, 1);
                                if (version == CacheVersion)
                                {
                                    var hash = Serializer.DeserializeWithLengthPrefix<string>(fs, PrefixStyle.Base128, 1);
                                    if (hash == CalcProjectHash())
                                    {
                                        _project.VarietyPairs.AddRange(Serializer.DeserializeItems<VarietyPairSurrogate>(fs, PrefixStyle.Base128, 1)
                                            .Select(surrogate => surrogate.ToVarietyPair(_segmentPool, _project)));
                                        delete = false;
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            // could not load the cache, so delete it
                        }
                    }
                    if (delete)
                        File.Delete(cacheFileName);
                }
            }

            if (vm != null)
                vm.Text = "Initializing views...";
            OnProjectOpened(new EventArgs());
        }
Exemple #23
0
        private bool MigrateProjectIfNeeded(ProgressViewModel vm, CogProject project)
        {
            if (project.Version == ProjectVersion)
                return false;

            vm.Text = "Updating project...";
            foreach (IProjectMigration pm in ProjectMigrations.SkipWhile(cm => project.Version >= cm.Version))
                pm.Migrate(_segmentPool, project);
            project.Version = ProjectVersion;
            return true;
        }
Exemple #24
0
 private void CloseProject()
 {
     if (_projectFileStream != null)
     {
         _projectFileStream.Close();
         _projectFileStream = null;
     }
     _project = null;
     _projectName = null;
     _isChanged = false;
 }
            public TestEnvironment()
            {
                DispatcherHelper.Initialize();
                _segmentPool = new SegmentPool();
                _projectService = Substitute.For<IProjectService>();
                _dialogService = Substitute.For<IDialogService>();
                var busyService = Substitute.For<IBusyService>();
                var exportService = Substitute.For<IExportService>();
                _analysisService = new AnalysisService(_spanFactory, _segmentPool, _projectService, _dialogService, busyService);

                WordPairsViewModel.Factory wordPairsFactory = () => new WordPairsViewModel(busyService);
                VarietyPairViewModel.Factory varietyPairFactory = (vp, order) => new VarietyPairViewModel(_segmentPool, _projectService, wordPairsFactory, vp, order);

                _varietyPairs = new VarietyPairsViewModel(_projectService, busyService, _dialogService, exportService, _analysisService, varietyPairFactory);

                _project = TestHelpers.GetTestProject(_spanFactory, _segmentPool);
                _projectService.Project.Returns(_project);
            }
            public TestEnvironment()
            {
                DispatcherHelper.Initialize();
                _projectService = Substitute.For<IProjectService>();
                var dialogService = Substitute.For<IDialogService>();
                var importService = Substitute.For<IImportService>();

                SegmentMappingViewModel.Factory mappingFactory = (segment1, segment2) => new SegmentMappingViewModel(_projectService, segment1, segment2);
                NewSegmentMappingViewModel.Factory newMappingFactory = () => new NewSegmentMappingViewModel(_projectService);

                var segmentMappings = new SegmentMappingsViewModel(dialogService, importService, mappingFactory, newMappingFactory);
                _segmentPair = new SegmentMappingsTableSegmentPairViewModel(segmentMappings, mappingFactory,
                    new SegmentMappingsTableSegmentViewModel(new Segment(FeatureStruct.New().Symbol(CogFeatureSystem.ConsonantType).Feature(CogFeatureSystem.StrRep).EqualTo("b").Value), SoundType.Consonant),
                    new SegmentMappingsTableSegmentViewModel(new Segment(FeatureStruct.New().Symbol(CogFeatureSystem.ConsonantType).Feature(CogFeatureSystem.StrRep).EqualTo("c").Value), SoundType.Consonant),
                    100, true);

                var project = new CogProject(_spanFactory);
                _projectService.Project.Returns(project);
            }
 public void OpenProject(CogProject project)
 {
     _projectService.Project.Returns(project);
     _projectService.ProjectOpened += Raise.Event();
     _wordListsViewModel.VarietiesView = new ListCollectionView(_wordListsViewModel.Varieties);
 }
Exemple #28
0
 protected Word ParseWordOnce(string wordText, Meaning meaning, CogProject project)
 {
     Word word;
     // We expect to see a lot of duplicates in our input text; save time by memoizing
     if (_parsedWords.TryGetValue(wordText, out word))
         return word;
     try
     {
         word = ParseWord(wordText, meaning);
     }
     catch (FormatException e)
     {
         Errors.Add(e.Message);
         return null;
     }
     project.Segmenter.Segment(word);
     _parsedWords.Add(wordText, word);
     return word;
 }
        public void Import()
        {
            var importer = new WordSurv6WordListsImporter();

            Assert.That(importer.CreateImportSettingsViewModel(), Is.Null);

            var project = new CogProject(_spanFactory)
                {
                    Varieties = {new Variety("variety")},
                    Meanings = {new Meaning("gloss", "cat")}
                };

            // empty file
            const string file1 = "";
            Assert.Throws<XmlException>(() => importer.Import(null, new MemoryStream(Encoding.Unicode.GetBytes(file1), false), project));

            // no meanings or varieties
            const string file2 = "<?xml version=\"1.0\" encoding=\"utf-16\"?><survey />";
            importer.Import(null, new MemoryStream(Encoding.Unicode.GetBytes(file2), false), project);
            Assert.That(project.Meanings, Is.Empty);
            Assert.That(project.Varieties, Is.Empty);

            // meanings only
            const string file3 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
                               + "<survey><glosses><gloss id=\"0\"><name>gloss1</name><part_of_speech>cat1</part_of_speech></gloss><gloss id=\"0\"><name>gloss2</name></gloss></glosses></survey>";
            importer.Import(null, new MemoryStream(Encoding.Unicode.GetBytes(file3), false), project);
            Assert.That(project.Meanings.Select(s => s.Gloss), Is.EqualTo(new[] {"gloss1", "gloss2"}));
            Assert.That(project.Meanings.Select(s => s.Category), Is.EqualTo(new[] {"cat1", null}));
            Assert.That(project.Varieties, Is.Empty);

            // varieties only
            const string file4 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
                               + "<survey><word_lists><word_list id=\"0\"><name>variety1</name></word_list><word_list id=\"1\"><name>variety2</name></word_list></word_lists></survey>";
            importer.Import(null, new MemoryStream(Encoding.Unicode.GetBytes(file4), false), project);
            Assert.That(project.Meanings, Is.Empty);
            Assert.That(project.Varieties.Select(v => v.Name), Is.EqualTo(new[] {"variety1", "variety2"}));

            // meanings, varieties, categories, and words
            const string file5 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
                               + "<survey>"
                               + "<word_lists><word_list id=\"0\"><name>variety1</name></word_list><word_list id=\"1\"><name>variety2</name></word_list></word_lists>"
                               + "<glosses>"
                               + "<gloss id=\"0\"><name>gloss1</name><part_of_speech>cat1</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word1</name></transcription><transcription><word_list_id>1</word_list_id><name>word4</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"1\"><name>gloss2</name><part_of_speech>cat2</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word2</name></transcription><transcription><word_list_id>1</word_list_id><name>word5</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"2\"><name>gloss3</name><part_of_speech>cat3</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word3</name></transcription><transcription><word_list_id>1</word_list_id><name>word6</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "</glosses>"
                               + "</survey>";
            importer.Import(null, new MemoryStream(Encoding.Unicode.GetBytes(file5), false), project);
            Assert.That(project.Meanings.Select(s => s.Gloss), Is.EqualTo(new[] {"gloss1", "gloss2", "gloss3"}));
            Assert.That(project.Meanings.Select(s => s.Category), Is.EqualTo(new[] {"cat1", "cat2", "cat3"}));
            Assert.That(project.Varieties.Select(v => v.Name), Is.EqualTo(new[] {"variety1", "variety2"}));
            Assert.That(project.Varieties.SelectMany(v => v.Words).Select(w => w.StrRep), Is.EqualTo(new[] {"word1", "word2", "word3", "word4", "word5", "word6"}));

            // no variety name
            const string file6 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
                               + "<survey>"
                               + "<word_lists><word_list id=\"0\"></word_list><word_list id=\"1\"><name>variety2</name></word_list></word_lists>"
                               + "<glosses>"
                               + "<gloss id=\"0\"><name>gloss1</name><part_of_speech>cat1</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word1</name></transcription><transcription><word_list_id>1</word_list_id><name>word4</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"1\"><name>gloss2</name><part_of_speech>cat2</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word2</name></transcription><transcription><word_list_id>1</word_list_id><name>word5</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"2\"><name>gloss3</name><part_of_speech>cat3</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word3</name></transcription><transcription><word_list_id>1</word_list_id><name>word6</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "</glosses>"
                               + "</survey>";
            Assert.Throws<ImportException>(() => importer.Import(null, new MemoryStream(Encoding.Unicode.GetBytes(file6), false), project));

            // no gloss
            const string file7 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
                               + "<survey>"
                               + "<word_lists><word_list id=\"0\"><name>variety1</name></word_list><word_list id=\"1\"><name>variety2</name></word_list></word_lists>"
                               + "<glosses>"
                               + "<gloss id=\"0\"><name>gloss1</name><part_of_speech>cat1</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word1</name></transcription><transcription><word_list_id>1</word_list_id><name>word4</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"1\"><part_of_speech>cat2</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word2</name></transcription><transcription><word_list_id>1</word_list_id><name>word5</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"2\"><name>gloss3</name><part_of_speech>cat3</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word3</name></transcription><transcription><word_list_id>1</word_list_id><name>word6</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "</glosses>"
                               + "</survey>";
            Assert.Throws<ImportException>(() => importer.Import(null, new MemoryStream(Encoding.Unicode.GetBytes(file7), false), project));

            // duplicate variety names
            const string file8 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
                               + "<survey>"
                               + "<word_lists><word_list id=\"0\"><name>variety1</name></word_list><word_list id=\"1\"><name>variety1</name></word_list></word_lists>"
                               + "<glosses>"
                               + "<gloss id=\"0\"><name>gloss1</name><part_of_speech>cat1</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word1</name></transcription><transcription><word_list_id>1</word_list_id><name>word4</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"1\"><name>gloss2</name><part_of_speech>cat2</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word2</name></transcription><transcription><word_list_id>1</word_list_id><name>word5</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"2\"><name>gloss3</name><part_of_speech>cat3</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word3</name></transcription><transcription><word_list_id>1</word_list_id><name>word6</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "</glosses>"
                               + "</survey>";
            Assert.Throws<ImportException>(() => importer.Import(null, new MemoryStream(Encoding.Unicode.GetBytes(file8), false), project));

            // duplicate glosses
            const string file9 = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
                               + "<survey>"
                               + "<word_lists><word_list id=\"0\"><name>variety1</name></word_list><word_list id=\"1\"><name>variety2</name></word_list></word_lists>"
                               + "<glosses>"
                               + "<gloss id=\"0\"><name>gloss1</name><part_of_speech>cat1</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word1</name></transcription><transcription><word_list_id>1</word_list_id><name>word4</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"1\"><name>gloss2</name><part_of_speech>cat2</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word2</name></transcription><transcription><word_list_id>1</word_list_id><name>word5</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "<gloss id=\"2\"><name>gloss1</name><part_of_speech>cat3</part_of_speech>"
                               + "<transcriptions><transcription><word_list_id>0</word_list_id><name>word3</name></transcription><transcription><word_list_id>1</word_list_id><name>word6</name></transcription></transcriptions>"
                               + "</gloss>"
                               + "</glosses>"
                               + "</survey>";
            Assert.Throws<ImportException>(() => importer.Import(null, new MemoryStream(Encoding.Unicode.GetBytes(file9), false), project));
        }
Exemple #30
0
 public void SetUp()
 {
     _segmentPool = new SegmentPool();
     _project = ConfigManager.Load(_spanFactory, _segmentPool, "Services\\ProjectMigrations\\ProjectMigration4Tests.cogx");
 }