public void EntryWithChildren() { Extensible extensibleInfo = new Extensible(); LexEntry e = MakeSimpleEntry(); LexSense s = _builder.GetOrMakeSense(e, extensibleInfo, string.Empty); LexExampleSentence ex = _builder.GetOrMakeExample(s, new Extensible()); ex.Sentence["foo"] = "this is a sentence"; ex.Translation["aa"] = "aaaa"; _builder.FinishEntry(e); CheckCompleteEntry(e); RepositoryId[] entries = _dataMapper.GetAllItems(); Assert.AreEqual(1, entries.Length); //now check it again, from the list CheckCompleteEntry(_dataMapper.GetItem(entries[0])); }
private void LoadLift(string path) { //Performance wise, the following is not expecting a huge, 10k word list. using (var reader = new Palaso.DictionaryServices.Lift.LiftReader(new NullProgressState(), WeSayWordsProject.Project.GetSemanticDomainsList(), WeSayWordsProject.Project.GetIdsOfSingleOptionFields())) using (var m = new MemoryDataMapper <LexEntry>()) { reader.Read(path, m); _words.AddRange(from RepositoryId repositoryId in m.GetAllItems() select m.GetItem(repositoryId)); } foreach (var word in _words) { foreach (var sense in word.Senses) { if (_glossMeaningField) { // copy all definition forms to gloss then delete definition form foreach (var form in sense.Definition.Forms) { //this check makes sure we don't introduce a form form a lang we allow for def, but not gloss if (_glossWritingSystemIds.Contains(form.WritingSystemId)) { sense.Gloss.SetAlternative(form.WritingSystemId, form.Form); } sense.Definition.SetAlternative(form.WritingSystemId, null); } } else { // copy all gloss forms to definition then delete gloss form foreach (var form in sense.Gloss.Forms) { //this check makes sure we don't introduce a form form a lang we allow for gloss, but not def if (_definitionWritingSystemIds.Contains(form.WritingSystemId)) { sense.Definition.SetAlternative(form.WritingSystemId, form.Form); } sense.Gloss.SetAlternative(form.WritingSystemId, null); } } } } }
private void LoadLift(string path) { //Performance wise, the following is not expecting a huge, 10k word list. using (var reader = new Palaso.DictionaryServices.Lift.LiftReader(new NullProgressState(), WeSayWordsProject.Project.GetSemanticDomainsList(), WeSayWordsProject.Project.GetIdsOfSingleOptionFields())) using (var m = new MemoryDataMapper <LexEntry>()) { reader.Read(path, m); _words.AddRange(from RepositoryId repositoryId in m.GetAllItems() select m.GetItem(repositoryId)); } }
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); }
public T GetItem(RepositoryId id) { return(_backend.GetItem(id)); }