Beispiel #1
0
        public CogProject GetDefaultProject()
        {
            var spanFactory = new ShapeSpanFactory();
            var segmentPool = new SegmentPool();

            return(VerbBase.GetProjectFromResource(spanFactory, segmentPool));
        }
Beispiel #2
0
 internal void SetupProject()         // Should this be protected? But the unit test needs to call it.
 {
     if (ConfigData != null && ConfigFilename != null)
     {
         Warnings.Add("WARNING: options --config-data and --config-file were both specified. Ignoring --config-file.");
         ConfigFilename = null;
     }
     if (ConfigData == null && ConfigFilename == null)
     {
         ConfigFilename = FindConfigFilename();
         // If ConfigFilename is STILL null at this point, it's because no config files were found at all,
         // so we'll use the default one from the resource.
     }
     SpanFactory = new ShapeSpanFactory();
     SegmentPool = new SegmentPool();
     if (ConfigData == null && ConfigFilename == null)
     {
         Project = GetProjectFromResource(SpanFactory, SegmentPool);
     }
     else if (ConfigData != null)
     {
         Project = GetProjectFromXmlString(SpanFactory, SegmentPool, ConfigData);
     }
     else if (ConfigFilename != null)
     {
         Project = GetProjectFromFilename(SpanFactory, SegmentPool, ConfigFilename);
     }
     else             // Should never get here given checks above, but let's be safe and write the check anyway
     {
         Project = GetProjectFromResource(SpanFactory, SegmentPool);
     }
 }
Beispiel #3
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                WriteHelp();
                return(0);
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("The FieldWorks project file could not be found.");
                return(1);
            }

            FwRegistryHelper.Initialize();
            FwUtils.InitializeIcu();
            Sldr.Initialize();
            var synchronizeInvoke = new SingleThreadedSynchronizeInvoke();
            var spanFactory       = new ShapeSpanFactory();

            var projectId = new ProjectIdentifier(args[0]);
            var logger    = new ConsoleLogger(synchronizeInvoke);
            var dirs      = new NullFdoDirectories();
            var settings  = new LcmSettings {
                DisableDataMigration = true
            };
            var progress = new NullThreadedProgress(synchronizeInvoke);

            Console.WriteLine("Loading FieldWorks project...");
            try
            {
                using (LcmCache cache = LcmCache.CreateCacheFromExistingData(projectId, "en", logger, dirs, settings, progress))
                {
                    Language language = HCLoader.Load(spanFactory, cache, logger);
                    Console.WriteLine("Loading completed.");
                    Console.WriteLine("Writing HC configuration file...");
                    XmlLanguageWriter.Save(language, args[1]);
                    Console.WriteLine("Writing completed.");
                }
                return(0);
            }
            catch (LcmFileLockedException)
            {
                Console.WriteLine("Loading failed.");
                Console.WriteLine("The FieldWorks project is currently open in another application.");
                Console.WriteLine("Close the application and try to run this command again.");
                return(1);
            }
            catch (LcmDataMigrationForbiddenException)
            {
                Console.WriteLine("Loading failed.");
                Console.WriteLine("The FieldWorks project was created with an older version of FLEx.");
                Console.WriteLine("Migrate the project to the latest version by opening it in FLEx.");
                return(1);
            }
        }
        private XmlLanguageLoader(string configPath, Action<Exception, string> errorHandler)
        {
            _configPath = configPath;
            _errorHandler = errorHandler;
            _spanFactory = new ShapeSpanFactory();

            _tables = new Dictionary<string, CharacterDefinitionTable>();
            _charDefs = new Dictionary<string, CharacterDefinition>();
            _mprFeatures = new Dictionary<string, MprFeature>();
            _natClasses = new Dictionary<string, NaturalClass>();
            _families = new Dictionary<string, LexFamily>();
            _morphemes = new Dictionary<string, Morpheme>();
            _allomorphs = new Dictionary<string, Allomorph>();
            _stemNames = new Dictionary<string, StemName>();
            _prules = new Dictionary<string, IPhonologicalRule>();
        }
        public ITranslationEngine Create(Engine engine)
        {
            string         hcSrcConfigFileName = Path.Combine(engine.ConfigDirectory, "src-hc.xml");
            string         hcTrgConfigFileName = Path.Combine(engine.ConfigDirectory, "trg-hc.xml");
            TransferEngine transferEngine      = null;

            if (File.Exists(hcSrcConfigFileName) && File.Exists(hcTrgConfigFileName))
            {
                var spanFactory    = new ShapeSpanFactory();
                var hcTraceManager = new TraceManager();

                Language srcLang    = XmlLanguageLoader.Load(hcSrcConfigFileName);
                var      srcMorpher = new Morpher(spanFactory, hcTraceManager, srcLang);

                Language trgLang    = XmlLanguageLoader.Load(hcTrgConfigFileName);
                var      trgMorpher = new Morpher(spanFactory, hcTraceManager, trgLang);

                transferEngine = new TransferEngine(srcMorpher, new SimpleTransferer(new GlossMorphemeMapper(trgMorpher)), trgMorpher);
            }
            return(transferEngine);
        }
Beispiel #6
0
            public TestEnvironment(bool?actualCognacy, bool predictedCognacy)
            {
                DispatcherHelper.Initialize();

                var segmentPool     = new SegmentPool();
                var spanFactory     = new ShapeSpanFactory();
                var projectService  = Substitute.For <IProjectService>();
                var analysisService = Substitute.For <IAnalysisService>();

                _project = TestHelpers.GetTestProject(spanFactory, segmentPool);
                _project.Varieties.AddRange(new[] { new Variety("variety1"), new Variety("variety2") });
                _project.Meanings.Add(new Meaning("meaning1", null));
                var word1 = new Word("wɜrd", _project.Meanings[0]);

                _project.Varieties[0].Words.Add(word1);
                _project.Segmenter.Segment(word1);
                var word2 = new Word("kɑr", _project.Meanings[0]);

                _project.Varieties[1].Words.Add(word2);
                _project.Segmenter.Segment(word2);

                var vp = new VarietyPair(_project.Varieties[0], _project.Varieties[1]);

                if (actualCognacy != null)
                {
                    _project.CognacyDecisions.Add(new CognacyDecision(vp.Variety1, vp.Variety2, _project.Meanings[0], (bool)actualCognacy));
                }

                _project.VarietyPairs.Add(vp);
                var wp = new WordPair(word1, word2)
                {
                    PredictedCognacy = predictedCognacy, ActualCognacy = actualCognacy
                };

                _project.VarietyPairs[0].WordPairs.Add(wp);

                projectService.Project.Returns(_project);
                _wordPairViewModel = new WordPairViewModel(projectService, analysisService, wp, true);
            }
Beispiel #7
0
 // Should this be protected? But the unit test needs to call it.
 public void SetUpProject()
 {
     if (ConfigData != null && ConfigFilename != null)
     {
         Warnings.Add("WARNING: options --config-data and --config-file were both specified. Ignoring --config-file.");
         ConfigFilename = null;
     }
     if (ConfigData == null && ConfigFilename == null)
     {
         ConfigFilename = FindConfigFilename();
         // If ConfigFilename is STILL null at this point, it's because no config files were found at all, so we'll use the default one from the resource.
     }
     SpanFactory = new ShapeSpanFactory();
     SegmentPool = new SegmentPool();
     Variety1 = new Variety("variety1");
     Variety2 = new Variety("variety2");
     Meaning = new Meaning("gloss1", "cat1");
     if (ConfigData == null && ConfigFilename == null)
         Project = GetProjectFromResource(SpanFactory, SegmentPool);
     else if (ConfigData != null)
         Project = GetProjectFromXmlString(SpanFactory, SegmentPool, ConfigData);
     else if (ConfigFilename != null)
         Project = GetProjectFromFilename(SpanFactory, SegmentPool, ConfigFilename);
     else // Should never get here given checks above, but let's be safe and write the check anyway
         Project = GetProjectFromResource(SpanFactory, SegmentPool);
     Project.Meanings.Add(Meaning);
     Project.Varieties.Add(Variety1);
     Project.Varieties.Add(Variety2);
     Project.VarietyPairs.Add(new VarietyPair(Variety1, Variety2));
 }
Beispiel #8
0
            public TestEnvironment(bool? actualCognacy, bool predictedCognacy)
            {
                DispatcherHelper.Initialize();

                var segmentPool = new SegmentPool();
                var spanFactory = new ShapeSpanFactory();
                var projectService = Substitute.For<IProjectService>();
                var analysisService = Substitute.For<IAnalysisService>();
                _project = TestHelpers.GetTestProject(spanFactory, segmentPool);
                _project.Varieties.AddRange(new[] {new Variety("variety1"), new Variety("variety2")});
                _project.Meanings.Add(new Meaning("meaning1", null));
                var word1 = new Word("wɜrd", _project.Meanings[0]);
                _project.Varieties[0].Words.Add(word1);
                _project.Segmenter.Segment(word1);
                var word2 = new Word("kɑr", _project.Meanings[0]);
                _project.Varieties[1].Words.Add(word2);
                _project.Segmenter.Segment(word2);

                var vp = new VarietyPair(_project.Varieties[0], _project.Varieties[1]);
                if (actualCognacy != null)
                    _project.CognacyDecisions.Add(new CognacyDecision(vp.Variety1, vp.Variety2, _project.Meanings[0], (bool) actualCognacy));

                _project.VarietyPairs.Add(vp);
                var wp = new WordPair(word1, word2) {PredictedCognacy = predictedCognacy, ActualCognacy = actualCognacy};
                _project.VarietyPairs[0].WordPairs.Add(wp);

                projectService.Project.Returns(_project);
                _wordPairViewModel = new WordPairViewModel(projectService, analysisService, wp, true);
            }
Beispiel #9
0
 public CogProject GetDefaultProject()
 {
     var spanFactory = new ShapeSpanFactory();
     var segmentPool = new SegmentPool();
     return VerbBase.GetProjectFromResource(spanFactory, segmentPool);
 }