public void FindWord(string word) { using (DudenCacheModel mdl = new DudenCacheModel()) { WordMatch match = mdl.WordMatches.Where(wm => wm.Word == word).FirstOrDefault(); if (match == null) { match = new WordMatch() { Word = word }; mdl.Add(match); mdl.SaveChanges(); } if (match.WordDefinition == null) { try { WebClient client = new WebClient(); string searchResults = client.DownloadString(string.Format("http://www.duden.de/suchen/dudenonline/{0}", word)); var link = ParseSearchResults(searchResults, "relativeLink").OfType<string>().First(s => !string.IsNullOrWhiteSpace(s)); var worddef = ParseSearchResults(searchResults, "word").OfType<string>().First(s => !string.IsNullOrWhiteSpace(s)); string resultPage = client.DownloadString(string.Format("http://www.duden.de{0}", link)); var synonyms = ParsePage(resultPage, "synonym").OfType<string>().Where(s => !string.IsNullOrWhiteSpace(s)); var wortart = ParsePage(resultPage, "wortart").OfType<string>().First(s => !string.IsNullOrWhiteSpace(s)); var frequency = int.Parse(ParsePage(resultPage, "frequency").OfType<string>().First(s => !string.IsNullOrWhiteSpace(s))); } catch (WebException wex) { } } } }
private IEnumerable <WordMatch> CombineParts(WordMatch wordMatch, IGrouping <int, string>[] parts) { foreach (var part in parts.SelectMany(x => x)) { if (!wordMatch.IsMatch(part)) { continue; } var clone = (WordMatch)wordMatch.Clone(); clone.Match(part); if (clone.IsComplete) { yield return(clone); } foreach (var match in CombineParts(clone, parts .Where(g => g.Key <= clone.RemainingCharCount) .ExcludePart(part) .ToArray())) { yield return(match); } } }
/// <summary> /// Validates the Sequences for all the general test cases. /// </summary> /// <param name="node">Xml Node Name</param> /// <param name="additionalParameter"> /// Additional Parameter based /// on which the validations are done. /// </param> private void ValidateComputeFeature(string node, AssemblyParameters additionalParameter) { // Get the parameters from Xml string firstSequence = utilityObj.xmlUtil.GetTextValue(node, Constants.SequenceNode1); string secondSequence = utilityObj.xmlUtil.GetTextValue(node, Constants.SequenceNode2); string kmerLength = utilityObj.xmlUtil.GetTextValue(node, Constants.KmerLengthNode); string expectedFeatureCount = utilityObj.xmlUtil.GetTextValue(node, Constants.FeatureCount); string expectedFeature = utilityObj.xmlUtil.GetTextValue(node, Constants.FeatureName); string expectedFeatureType = utilityObj.xmlUtil.GetTextValue(node, Constants.FeatureType); string expectedStartIndex = utilityObj.xmlUtil.GetTextValue(node, Constants.StartIndexNode); string expectedEndIndex = utilityObj.xmlUtil.GetTextValue(node, Constants.EndIndexNode); ISequence seq1 = null; ISequence seq2 = null; // Create Sequences. switch (additionalParameter) { case AssemblyParameters.Assemble: var seqObj1 = new Sequence(Alphabets.Protein, firstSequence); var seqObj2 = new Sequence(Alphabets.Protein, secondSequence); seq1 = seqObj1; seq2 = seqObj2; break; case AssemblyParameters.Consensus: seq1 = new Sequence(Alphabets.DNA, firstSequence); seq2 = new Sequence(Alphabets.DNA, secondSequence); break; } var kmerBuilder = new SequenceToKmerBuilder(); KmersOfSequence kmerList = kmerBuilder.Build(seq1, int.Parse(kmerLength, null)); List <WordMatch> nodes = WordMatch.BuildMatchTable( kmerList, seq2, int.Parse(kmerLength, null)); List <WordMatch> matchList = WordMatch.GetMinimalList(nodes, int.Parse(kmerLength, null)); List <DifferenceNode> diffNode = DifferenceNode.BuildDiffList(matchList, seq1, seq2); List <DifferenceNode.CompareFeature> features = DifferenceNode.OutputDiffList(diffNode, seq1, seq2); // Validate difference. Assert.AreEqual(expectedFeatureCount, features.Count.ToString((IFormatProvider)null)); Assert.AreEqual(expectedFeature, features[0].Feature); Assert.AreEqual(expectedFeatureType, features[0].FeatureType); Assert.AreEqual(expectedStartIndex, features[0].Start.ToString((IFormatProvider)null)); Assert.AreEqual(expectedEndIndex, features[0].End.ToString((IFormatProvider)null)); ApplicationLog.WriteLine(string.Format(null, "Kmer P1 : Validated DifferenceNodes successfully.")); }
public static void FindDifferencesInSequences(string firstFile, string secondFile) { // parsowanie pierwszej listy if (!SequenceParsers.IsFasta(firstFile)) { Console.WriteLine("Nieprawidlowy format pierwszego pliku!"); return; } if (!SequenceParsers.IsFasta(secondFile)) { Console.WriteLine("Nieprawidlowy format drugiego pliku!"); return; } var firstParser = SequenceParsers.FindParserByFileName(firstFile); firstParser.Alphabet = AmbiguousProteinAlphabet.Instance; var firstSequenceList = firstParser.Parse(); var firstFileSequences = Helper.ConvertIenumerableToList(firstSequenceList); // parsowanie drugiej listy var secondParser = SequenceParsers.FindParserByFileName(firstFile); secondParser.Alphabet = AmbiguousProteinAlphabet.Instance; var secondSequenceList = secondParser.Parse(); var secondFileSequences = Helper.ConvertIenumerableToList(secondSequenceList); // pobranie listy KMER'ów var kmerBuilder = new SequenceToKmerBuilder(); var kmerList = kmerBuilder.Build(firstFileSequences.First(), 2); var nodes = WordMatch.BuildMatchTable(kmerList, secondFileSequences.First(), 2); var list2 = new List <WordMatch>(nodes); var matchList = WordMatch.GetMinimalList(list2, 2); var list3 = new List <WordMatch>(matchList); // znajdŸ ró¿nice miêdzy wêz³ami var diffNode = DifferenceNode.BuildDiffList(list3, firstFileSequences.First(), secondFileSequences.First()); var list4 = new List <DifferenceNode>(diffNode); var features = DifferenceNode.OutputDiffList(list4, firstFileSequences.First(), secondFileSequences.First()); foreach (var compareFeature in features) { Console.WriteLine(compareFeature.Feature); } }
public object Clone() { var partsClone = new string[_parts.Count]; _parts.CopyTo(partsClone); var clone = new WordMatch(Word, _logger) { _remainder = _remainder, _parts = partsClone.ToList() }; _logger($"Cloning [{GetHashCode()}] to [{clone.GetHashCode()}]"); return(clone); }
public IEnumerable <WordMatch> GetMatches(string[] s) { var lowerWord = Word.ToLower(); var lowerTarget = s[0].ToLower(); var isMatch = lowerWord == lowerTarget.ToCSharpName() || lowerWord == lowerTarget; if (!isMatch) { return(WordMatch.NoMatch()); } return(new[] { new WordMatch(1, s[0]) }); }
public override IEnumerable <WordMatch> GetMatches(string[] s) { var enumValues = Enum.GetValues(ParamInfo.ParameterType); foreach (var enumValue in enumValues) { if (IsMatch(enumValue, s)) { return new[] { BuildWordMatch(enumValue.ToString(), s) } } ; } return(WordMatch.NoMatch()); }
public void SequenceCompare() { ISequence seq1 = new Sequence(Alphabets.DNA, "AAAAAA"); ISequence seq2 = new Sequence(Alphabets.DNA, "AAATAA"); SequenceToKmerBuilder kmerBuilder = new SequenceToKmerBuilder(); KmersOfSequence kmers = kmerBuilder.Build(seq1, 2); List <WordMatch> nodes = WordMatch.BuildMatchTable(kmers, seq1, seq2, 2); List <WordMatch> matchList = WordMatch.GetMinimalList(nodes, 2); List <DifferenceNode> diffNode = DifferenceNode.BuildDiffList(matchList, seq1, seq2); List <DifferenceNode.CompareFeature> features = DifferenceNode.OutputDiffList(diffNode, seq1, seq2); Assert.AreEqual(features.Count, 4); Assert.AreEqual(features[0].Feature, "Insertion of 1 bases in 2 "); Assert.AreEqual(features[1].FeatureType, "REPLACE"); Assert.AreEqual(features[2].Feature, "Insertion of 1 bases in 1 "); Assert.AreEqual(features[3].FeatureType, "REPLACE"); }
public void ValidateSequenceCompare() { string firstSequence = utilityObj.xmlUtil.GetTextValue(Constants.SequenceCompareNode, Constants.SequenceNode1); string secondSequence = utilityObj.xmlUtil.GetTextValue(Constants.SequenceCompareNode, Constants.SequenceNode2); string replace = utilityObj.xmlUtil.GetTextValue(Constants.SequenceCompareNode, Constants.ReplaceNode); ISequence seq1 = new Sequence(Alphabets.DNA, firstSequence); ISequence seq2 = new Sequence(Alphabets.DNA, secondSequence); var kmerBuilder = new SequenceToKmerBuilder(); KmersOfSequence kmers = kmerBuilder.Build(seq1, 2); List <WordMatch> nodes = WordMatch.BuildMatchTable(kmers, seq2, 2); List <WordMatch> matchList = WordMatch.GetMinimalList(nodes, 2); List <DifferenceNode> diffNode = DifferenceNode.BuildDiffList(matchList, seq1, seq2); List <DifferenceNode.CompareFeature> features = DifferenceNode.OutputDiffList(diffNode, seq1, seq2); //Validating the bahavior. Assert.AreEqual(features.Count, 4); Assert.AreEqual(features[0].Feature, Constants.InsertionOfOneBaseIn2); Assert.AreEqual(features[1].FeatureType, replace); Assert.AreEqual(features[2].Feature, Constants.InsertionOfOneBaseIn1); Assert.AreEqual(features[3].FeatureType, replace); }
public static List <TransliterationRule> Recognize( Language sourceLanguage, Language resultLanguage, IEnumerable <WordInLangs> wordTextTranslations) { var wordGraphemeTranslations = ( from t in wordTextTranslations let match = WordMatch.Create(t.Lang1Word, t.Lang2Word, sourceLanguage, resultLanguage) where match.Success select GraphemeTranslation.Create(match.LetterMatches, sourceLanguage.ToGraphemes(t.Lang1Word)) ).ToList(); var correctedGraphemeTranslations = RuleRecognizer.CorrectGraphemeLengths(sourceLanguage, wordGraphemeTranslations); var allGraphemeTranslations = Db.EngToRusMap .Select(x => new GraphemeTranslation(sourceLanguage.ToGrapheme(x.eng.ToString()), x.rus)) .Union(correctedGraphemeTranslations); var rules = RuleRecognizer.CreateTranslationRules(allGraphemeTranslations); return(rules); }
public WordMatchView(WordMatch wordMatch) { this.WordMatch = wordMatch; InitializeComponent(); }
public static void dummyMethodForParallelLooping(string file, WordMatch result, int resultsCount, int wordsCount) { }
public WordsSimilarity(string lang1Word, string?lang2Word, WordMatch matchInfo) { this.Lang1Word = lang1Word ?? throw new ArgumentNullException(nameof(lang1Word)); this.Lang2Word = lang2Word ?? throw new ArgumentNullException(nameof(lang2Word)); this.MatchInfo = matchInfo ?? throw new ArgumentNullException(nameof(matchInfo)); }
/// <summary> /// Comparison of two word match list nodes /// based on the first sequence start indices /// </summary> /// <param name="n1">First match list node</param> /// <param name="n2">Second match list node</param> /// <returns>Integer value indicating zero if equal.</returns> public static int CompareDifferenceNode(WordMatch n1, WordMatch n2) { if (n1 == null) { throw new ArgumentNullException("n1"); } if (n2 == null) { throw new ArgumentNullException("n2"); } return n1.Sequence1Start - n2.Sequence1Start; }
public CustomWordMatch(WordMatch wordMatch, string synonymOf) { Index = wordMatch.Index; Word = wordMatch.Word; SynonymOf = synonymOf; }
public CustomWordMatch(WordMatch wordMatch) { Index = wordMatch.Index; Word = wordMatch.Word; }