public void XmlWordNetParser() { var parser = new XmlWordNetParser(); var result = parser.Parse("TestData/wordnet.xml", true); Assert.NotNull(result); Assert.Equal(2, result.LexicalEntries.Count()); var lexicalEntry = result.LexicalEntries.First(); Assert.Equal("ewn-wordnet-n", lexicalEntry.Id); Assert.Equal("en", lexicalEntry.Language); Assert.Equal("wordnet", lexicalEntry.Lemma); Assert.Equal(PartOfSpeech.Noun, lexicalEntry.PartOfSpeech); Assert.Single(lexicalEntry.Senses); var sense = lexicalEntry.Senses.First(); Assert.Equal("ewn-wordnet-n-06652077-01", sense.Id); Assert.Equal("01", sense.PositionInSynset); Assert.NotNull(sense.Synset); var synset = sense.Synset; Assert.Equal("ewn-06652077-n", synset.Id); Assert.Equal("any of the machine-readable lexical databases modeled after the Princeton WordNet", synset.Definitions.First()); Assert.Equal(PartOfSpeech.Noun, synset.PartOfSpeech); Assert.Single(result.SenseRelations); Assert.Equal(4, result.SynsetRelations.Count()); }
private static void Main(string[] args) { bool shouldShowHelp = false; bool loadRelations = true; string wordNetFile = string.Empty; string connectionString = string.Empty; var options = new OptionSet { { "f|file=", "WordNet file to process,", f => wordNetFile = f }, { "c|connection=", "connection string,", cs => connectionString = cs }, { "nr|no-relations", "relations will not be imported,", _ => loadRelations = false }, { "h|help", "show this message and exit.", h => shouldShowHelp = h != null }, }; try { var extra = options.Parse(args); if (shouldShowHelp || extra.Any()) { ShowHelp(options); return; } var message = string.Empty; if (string.IsNullOrEmpty(wordNetFile)) { message += "Missing required option '-f'. "; } if (string.IsNullOrEmpty(connectionString)) { message += "Missing required option '-c'"; } if (!string.IsNullOrEmpty(message)) { throw new InvalidOperationException(message); } var parser = new XmlWordNetParser(); var result = parser.Parse(wordNetFile, loadRelations); var optionsBuilder = new DbContextOptionsBuilder <WordNetDbContext>(); optionsBuilder.UseSqlite(connectionString); using var db = new WordNetDbContext(optionsBuilder.Options); Console.WriteLine("Saving into db. This will take a while."); db.AddRange(result.LexicalEntries); if (loadRelations) { db.AddRange(result.SenseRelations); db.AddRange(result.SynsetRelations); } var entries = db.SaveChanges(); Console.WriteLine($"Number of entries written to db: {entries}."); } catch (Exception e) { Console.Write($"{Name}: "); Console.WriteLine(e.Message); Console.WriteLine($"\nTry `{Name} --help' for more information."); return; } }