public void TestSortBySimilarity() { string lexiquePath = @"C:\Users\VR1\source\repos\phonos\data\Lexique383.tsv"; var nouns = LexiqueParser.ParseLexique(lexiquePath) .Where(e => e.POS == "NOM") .ToArray(); var phoneticDistance = new PhoneticDistance(new SyllableDistance(Distances.Distances.NeighborhoodVowelDistance, Distances.Distances.NeighborhoodConsonantDistance)); var realizationComputer = new RealizationComputer(); var rng = new Random(); var reference = realizationComputer.Compute(nouns[rng.Next(nouns.Length)]).Single(); var res = new List <Tuple <double, Realization> >(); foreach (var noun in nouns) { var realization = realizationComputer.Compute(noun).Single(); var distance = phoneticDistance.GetDistance(reference, realization); var similarity = 1 / (1 + distance); res.Add(Tuple.Create(similarity, realization)); } var sorted = res.OrderByDescending(t => t.Item1).ToArray(); }
public static NeighborhoodBuilder Init(string lexiquePath) { var nouns = LexiqueParser.ParseLexique(lexiquePath) .Where(e => e.POS == "NOM") .Select(e => new WordForm(e.WordForm, _realizationComputer.Compute(e))) .ToArray(); var nounsByForm = nouns.ToLookup(e => e.GraphicForm); return(new NeighborhoodBuilder(nouns, nounsByForm)); }
public void TestParseLine() { string line = "grumeleuses\tgRym°l2z\tgrumeleux\tADJ\tf\tp\t0.33\t1.89\t0.02\t0.14\t\t1\t2\t0\t11\t8\tCCVCVCVVCVC\tCCVCVCVC\t0\t0\t0\t0\tgRy-m°-l2z\t3\tCCV-CV-CVC\tsesuelemurg\tz2l°myRg\tgru-me-leu-ses\tADJ\t63\t19\t3.4\t\tgrumeleux\t1\n"; var expected = new LexiqueEntry("grumeleuses", "grumeleux", "ADJ", phonemes: new[] { new ContextualPhoneme(Phonemes.g), new ContextualPhoneme(Phonemes.R), new ContextualPhoneme(Phonemes.y), new ContextualPhoneme(Phonemes.m), new ContextualPhoneme(Phonemes._e, isElidable: true), new ContextualPhoneme(Phonemes.l), new ContextualPhoneme(Phonemes.eu), new ContextualPhoneme(Phonemes.z), }); var entry = LexiqueParser.ParseEntry(line); Assert.Equal(expected, entry); }
public void TestComputeAllNounDistances() { string lexiquePath = @"C:\Users\VR1\source\repos\phonos\data\Lexique383.tsv"; var nouns = LexiqueParser.ParseLexique(lexiquePath) .Where(e => e.POS == "NOM") .ToArray(); var phoneticDistance = new PhoneticDistance(new SyllableDistance(Distances.Distances.NeighborhoodVowelDistance, Distances.Distances.NeighborhoodConsonantDistance)); var realizationComputer = new RealizationComputer(); var res = new List <Tuple <double, Realization, Realization> >(); foreach ((var n1, var n2) in nouns.UnorderedPairs()) { var r1 = realizationComputer.Compute(n1).Single(); var r2 = realizationComputer.Compute(n2).Single(); var distance = phoneticDistance.GetDistance(r1, r2); var similarity = 1 / (1 + distance); res.Add(Tuple.Create(similarity, r1, r2)); } var sorted = res.OrderByDescending(t => t.Item1).ToArray(); }
public void TestParseLexique() { string lexiquePath = @"C:\Users\VR1\source\repos\phonos\data\Lexique383.tsv"; var nouns = LexiqueParser.ParseLexique(lexiquePath) .ToArray(); }