Example #1
0
        protected override ReturnCode DoWork(TextReader inputReader, TextWriter outputWriter, TextWriter errorWriter)
        {
            ReturnCode retcode = ReturnCode.Okay;

            SetupProject();
            var variety = new Variety("variety1");

            Project.Varieties.Add(variety);
            Meaning meaning = MeaningFactory.Create();

            Project.Meanings.Add(meaning);
            IProcessor <Variety> syllabifier = Project.VarietyProcessors[ComponentIdentifiers.Syllabifier];

            foreach (string line in ReadLines(inputReader))
            {
                string wordText = line;                 // In the future we might need to split the line into multiple words
                try
                {
                    Word word = ParseWord(wordText, meaning);
                    Project.Segmenter.Segment(word);
                    variety.Words.Add(word);
                }
                catch (FormatException e)
                {
                    Errors.Add(line, e.Message);
                }
            }
            syllabifier.Process(variety);
            foreach (Word word in variety.Words)
            {
//				output.WriteLine("{0} {1} {2}", word.StemIndex, word.StemLength, word.ToString().Replace(" ", ""));
                outputWriter.WriteLine(word.ToString().Replace(" ", ""));
            }
            return(retcode);
        }
Example #2
0
        protected override ReturnCode DoWork(TextReader inputReader, TextWriter outputWriter, TextWriter errorWriter)
        {
            ReturnCode retcode = ReturnCode.Okay;

            SetupProject();
            var variety1 = new Variety("variety1");
            var variety2 = new Variety("variety2");

            Project.Varieties.Add(variety1);
            Project.Varieties.Add(variety2);
            Project.VarietyPairs.Add(new VarietyPair(variety1, variety2));

            foreach (string line in ReadLines(inputReader))
            {
                Meaning meaning = MeaningFactory.Create();
                Project.Meanings.Add(meaning);
                string[] wordTexts = line.Split(' ');
                if (wordTexts.Length != 2)
                {
                    Errors.Add(line, "Each line should have two space-separated words in it.");
                    continue;
                }
                Word[] words = wordTexts.Select(wordText => ParseWord(wordText, meaning)).ToArray();
                if (words.Length != 2 || words.Any(w => w == null))
                {
                    Errors.Add(line, "One or more of this line's words failed to parse. Successfully parsed words: {0}",
                               string.Join(", ", words.Where(w => w != null).Select(w => w.StrRep)));
                    continue;
                }

                variety1.Words.Add(words[0]);
                variety2.Words.Add(words[1]);
            }

            SegmentAll();

            foreach (VarietyPair varietyPair in Project.VarietyPairs)
            {
                Compare(varietyPair);
                foreach (WordPair wordPair in varietyPair.WordPairs)
                {
                    // Output format: "word1 word2 True/False score" where True means cognate and False means not cognate,
                    // and score is a number between 0.0 and 1.0
                    outputWriter.WriteLine("{0} {1} {2} {3}", wordPair.Word1.StrRep, wordPair.Word2.StrRep, wordPair.Cognacy,
                                           wordPair.PredictedCognacyScore);
                }
            }

            return(retcode);
        }
Example #3
0
        protected override ReturnCode DoWork(TextReader inputReader, TextWriter outputWriter, TextWriter errorWriter)
        {
            ReturnCode retcode = ReturnCode.Okay;

            if (!RawScores && !NormalizedScores)
            {
                Warnings.Add("Neither raw scores nor normalized scores were selected. Defaulting to normalized.");
                RawScores        = false;
                NormalizedScores = true;
            }
            if (RawScores && NormalizedScores)
            {
                Warnings.Add("Please specify either raw or normalized scores, but not both. Defaulting to normalized.");
                RawScores        = false;
                NormalizedScores = true;
            }

            SetupProject();
            Meaning meaning = MeaningFactory.Create();

            IWordAligner wordAligner = Project.WordAligners["primary"];

            foreach (string line in ReadLines(inputReader))
            {
                string[] wordTexts = line.Split(' ');
                if (wordTexts.Length != 2)
                {
                    Errors.Add(line, "Each line should have two space-separated words in it.");
                    continue;
                }
                Word[] words = wordTexts.Select(wordText => ParseWordOnce(wordText, meaning, Project)).ToArray();
                if (words.Length != 2 || words.Any(w => w == null))
                {
                    Errors.Add(line, "One or more of this line's words failed to parse. Successfully parsed words: {0}",
                               string.Join(", ", words.Where(w => w != null).Select(w => w.StrRep)));
                    continue;
                }
                IWordAlignerResult          result    = wordAligner.Compute(words[0], words[1]);
                Alignment <Word, ShapeNode> alignment = result.GetAlignments().First();
                outputWriter.WriteLine("{0} {1} {2}", words[0].StrRep, words[1].StrRep,
                                       RawScores ? alignment.RawScore : alignment.NormalizedScore);
                if (Verbose)
                {
                    outputWriter.Write(alignment.ToString(Enumerable.Empty <string>()));
                    outputWriter.WriteLine();
                }
            }

            return(retcode);
        }