Beispiel #1
0
        public void Setup()
        {
            _projectDir = new ProjectDirectorySetupForTesting("");
            _project    = _projectDir.CreateLoadedProject();
            _project.WritingSystems.Set(WritingSystemDefinition.Parse("fr"));
            _repo  = _project.GetLexEntryRepository();
            _entry = _repo.CreateItem();
            _entry.LexicalForm.SetAlternative("qaa-x-qaa", "apple");


            _project.DefaultPrintingTemplate.GetField(LexSense.WellKnownProperties.Definition).WritingSystemIds.Add("fr");
            _project.DefaultPrintingTemplate.GetField(LexExampleSentence.WellKnownProperties.Translation).WritingSystemIds.Add("fr");

            _project.DefaultPrintingTemplate.GetField(LexEntry.WellKnownProperties.CrossReference).Enabled = true;
        }
Beispiel #2
0
            public EnvironmentForTest()
            {
                ErrorReport.IsOkToInteractWithUser = false;
                const string xmlOfEntries = @" <entry id='foo1'>
						<lexical-unit><form lang='qaa-x-qaa'><text>hello</text></form></lexical-unit>
					</entry>"                    ;

                _testProject = new ProjectDirectorySetupForTesting(xmlOfEntries);
                _project     = _testProject.CreateLoadedProject();
                _projectInfo = _project.GetProjectInfoForAddin();

                string sourceTemplateDir = Path.Combine(_projectInfo.PathToApplicationRootDirectory, String.Format("..{0}..{0}templates", Path.DirectorySeparatorChar));

                TestUtilities.DeleteFolderThatMayBeInUse(OutputTemplateDir);
                CopyFolder(sourceTemplateDir, OutputTemplateDir);
            }
Beispiel #3
0
        public void OpenProject_OpenedWithDirNameWhichDoesNotMatchProjectName_Opens()
        {
            using (var projectDir = new ProjectDirectorySetupForTesting(""))
            {
                Palaso.UI.WindowsForms.Keyboarding.KeyboardController.Initialize();
                using (var window = new ConfigurationWindow(new string[] { }))
                {
                    Assert.AreNotEqual(
                        Path.GetFileNameWithoutExtension(projectDir.PathToLiftFile),
                        Path.GetFileName(projectDir.PathToDirectory));

                    window.DisableBackupAndChorusStuffForTests();
                    window.Show();
                    Assert.IsTrue(window.OpenProject(projectDir.PathToDirectory));
                }
                Palaso.UI.WindowsForms.Keyboarding.KeyboardController.Shutdown();
            }
        }
Beispiel #4
0
        public void Setup()
        {
            string entriesXml =
                @"<entry id='foo1'><lexical-unit><form lang='qaa-x-qaa'><text>fooOne</text></form></lexical-unit></entry>
								<entry id='foo2'><lexical-unit><form lang='qaa-x-qaa'><text>fooTwo</text></form></lexical-unit></entry>
								<entry id='foo3'><lexical-unit><form lang='qaa-x-qaa'><text>fooThree</text></form></lexical-unit></entry>"                                ;

            _projectDirectory = new ProjectDirectorySetupForTesting(entriesXml);

            _project = new WeSayWordsProject();
            _project.LoadFromLiftLexiconPath(_projectDirectory.PathToLiftFile);
            _tabbedForm    = new TabbedForm(new NullStatusBarController());
            _project.Tasks = new List <ITask>();
            _dashboardTask = new MockTask("Dashboard", "The control center.", true);
            _project.Tasks.Add(_dashboardTask);
            _dictionaryTask = new MockDictionaryTask("Dictionary blah blah", "The whole lexicon.", true);
            _project.Tasks.Add(_dictionaryTask);

            _tabbedForm.InitializeTasks(_project.Tasks);
        }
Beispiel #5
0
        static int Main(string[] args)
        {
            var options = new Options();
            var isValid = CommandLine.Parser.Default.ParseArgumentsStrict(args, options);

            if (isValid)
            {
                if (options.ShowHelp)
                {
                    Console.WriteLine(options.GetUsage());
                    return(0);
                }
                if (!File.Exists(options.InputFile))
                {
                    Console.WriteLine("Input lift wordlist {0} does not exist", options.InputFile);
                    return(1);
                }

                if ((options.OutputFile != "Wordlist.json") && File.Exists(options.OutputFile))
                {
                    Console.WriteLine("The file {0} already exists.", options.OutputFile);
                    return(1);
                }
                if (options.Verbose)
                {
                    Console.WriteLine("Input file: {0}", options.InputFile);
                    Console.WriteLine("Output file: {0}", options.OutputFile);
                }
            }
            else
            {
                // Display the default usage information
                Console.WriteLine("command line parsing failed");
                Console.WriteLine(options.GetUsage());
                return(1);
            }

            List <LexEntry> _words;

            _words = new List <LexEntry>();

            using (ProjectDirectorySetupForTesting p = new ProjectDirectorySetupForTesting("<entry id='foo1'><lexical-unit><form lang='qaa-x-qaa'><text>fooOne</text></form></lexical-unit></entry>"))
            {
                WeSayWordsProject project = p.CreateLoadedProject();

                using (var reader = new Palaso.DictionaryServices.Lift.LiftReader(new NullProgressState(),
                                                                                  WeSayWordsProject.Project.GetSemanticDomainsList(),
                                                                                  WeSayWordsProject.Project.GetIdsOfSingleOptionFields()))
                    using (var m = new MemoryDataMapper <LexEntry>())
                    {
                        reader.Read(options.InputFile, m);
                        _words.AddRange(from RepositoryId repositoryId in m.GetAllItems() select m.GetItem(repositoryId));
                    }
                foreach (var word in _words)
                {
                    foreach (var sense in word.Senses)
                    {
                        // copy all definition forms to gloss then delete definition form
                        foreach (var form in sense.Definition.Forms)
                        {
                            sense.Gloss.SetAlternative(form.WritingSystemId, form.Form);
                            sense.Definition.SetAlternative(form.WritingSystemId, null);
                        }
                    }
                }

                using (StreamWriter file = new StreamWriter(options.OutputFile))
                {
                    using (JsonWriter writer = new JsonTextWriter(file))
                    {
                        writer.WriteStartArray();
                        foreach (LexEntry word in _words)
                        {
                            writer.WriteStartObject();

                            writer.WritePropertyName("lexicalid");
                            LanguageForm idform    = word.LexicalForm.Find("en");
                            string       lexicalid = (idform == null ? word.LexicalForm.GetFirstAlternative() : idform.Form);
                            writer.WriteValue(lexicalid);

                            foreach (var sense in word.Senses)
                            {
                                foreach (var form in sense.Gloss.Forms)
                                {
                                    writer.WritePropertyName(form.WritingSystemId);
                                    writer.WriteValue(form.Form);
                                }
                            }

                            writer.WriteEndObject();
                        }
                        writer.WriteEndArray();
                    }
                }
            }
            return(0);
        }