public void FullTextConfigSerializeFullTextOptimiser() { try { IndexWriter writer = new IndexWriter(LuceneTestHarness.Index, LuceneTestHarness.Analyzer, IndexWriter.MaxFieldLength.UNLIMITED); writer.Dispose(); FullTextOptimiser optimiser = new FullTextOptimiser(new LuceneSearchProvider(LuceneTestHarness.LuceneVersion, LuceneTestHarness.Index, LuceneTestHarness.Schema)); ConfigurationSerializationContext context = new ConfigurationSerializationContext(); INode obj = context.Graph.CreateBlankNode(); context.NextSubject = obj; optimiser.SerializeConfiguration(context); TestTools.ShowGraph(context.Graph); ConfigurationLoader.AutoConfigureObjectFactories(context.Graph); Object temp = ConfigurationLoader.LoadObject(context.Graph, obj); Assert.IsTrue(temp is FullTextOptimiser, "Should have returned a LucenePredicatesIndexer instance"); Assert.IsTrue(temp is IAlgebraOptimiser, "Should have returned a IFullTextIndexer instance"); } finally { LuceneTestHarness.Index.Dispose(); } }
public void FullTextConfigSerializeAnalyzerLuceneStandard() { StandardAnalyzer analyzer = new StandardAnalyzer(LuceneTestHarness.LuceneVersion); ConfigurationSerializationContext context = new ConfigurationSerializationContext(); INode obj = context.Graph.CreateBlankNode(); context.NextSubject = obj; analyzer.SerializeConfiguration(context); TestTools.ShowGraph(context.Graph); ConfigurationLoader.AutoConfigureObjectFactories(context.Graph); Object temp = ConfigurationLoader.LoadObject(context.Graph, obj); Assert.IsTrue(temp is StandardAnalyzer, "Should have returned a StandardAnalyzer instance"); Assert.IsTrue(temp is Analyzer, "Should have returned a Analyzer instance"); }
public void FullTextConfigSerializeIndexLuceneRAM() { RAMDirectory directory = new RAMDirectory(); ConfigurationSerializationContext context = new ConfigurationSerializationContext(); INode obj = context.Graph.CreateBlankNode(); context.NextSubject = obj; directory.SerializeConfiguration(context); TestTools.ShowGraph(context.Graph); ConfigurationLoader.AutoConfigureObjectFactories(context.Graph); Object temp = ConfigurationLoader.LoadObject(context.Graph, obj); Assert.IsTrue(temp is RAMDirectory, "Should have returned a RAMDirectory instance"); Assert.IsTrue(temp is Directory, "Should have returned a Directory instance"); }
public void FullTextConfigSerializeSchemaDefault() { DefaultIndexSchema schema = new DefaultIndexSchema(); ConfigurationSerializationContext context = new ConfigurationSerializationContext(); INode obj = context.Graph.CreateBlankNode(); context.NextSubject = obj; schema.SerializeConfiguration(context); TestTools.ShowGraph(context.Graph); ConfigurationLoader.AutoConfigureObjectFactories(context.Graph); Object temp = ConfigurationLoader.LoadObject(context.Graph, obj); Assert.IsTrue(temp is DefaultIndexSchema, "Should have returned a DefaultIndexSchema instance"); Assert.IsTrue(temp is IFullTextIndexSchema, "Should have returned a IFullTextIndexSchema instance"); }
public void FullTextConfigSerializeIndexerLucenePredicates() { LucenePredicatesIndexer indexer = new LucenePredicatesIndexer(LuceneTestHarness.Index, LuceneTestHarness.Analyzer, LuceneTestHarness.Schema); ConfigurationSerializationContext context = new ConfigurationSerializationContext(); INode obj = context.Graph.CreateBlankNode(); context.NextSubject = obj; indexer.SerializeConfiguration(context); indexer.Dispose(); TestTools.ShowGraph(context.Graph); ConfigurationLoader.AutoConfigureObjectFactories(context.Graph); Object temp = ConfigurationLoader.LoadObject(context.Graph, obj); Assert.IsTrue(temp is LucenePredicatesIndexer, "Should have returned a LucenePredicatesIndexer instance"); Assert.IsTrue(temp is IFullTextIndexer, "Should have returned a IFullTextIndexer instance"); }
public void FullTextConfigSerializeIndexLuceneFS() { FSDirectory directory = FSDirectory.Open(new DirInfo("test")); ConfigurationSerializationContext context = new ConfigurationSerializationContext(); INode obj = context.Graph.CreateBlankNode(); context.NextSubject = obj; directory.SerializeConfiguration(context); directory.Dispose(); TestTools.ShowGraph(context.Graph); ConfigurationLoader.AutoConfigureObjectFactories(context.Graph); Object temp = ConfigurationLoader.LoadObject(context.Graph, obj); Assert.True(temp is FSDirectory, "Should have returned a FSDirectory instance"); Assert.True(temp is Directory, "Should have returned a Directory instance"); }
public void StorageVirtuosoConfigSerialization() { NTriplesFormatter formatter = new NTriplesFormatter(); VirtuosoManager manager = VirtuosoTest.GetConnection(); try { Assert.IsNotNull(manager); Graph g = new Graph(); INode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); INode dnrType = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyType)); INode objFactory = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.ClassObjectFactory)); INode virtFactory = g.CreateLiteralNode("VDS.RDF.Configuration.VirtuosoObjectFactory, dotNetRDF.Data.Virtuoso"); INode genericManager = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.ClassStorageProvider)); INode virtManager = g.CreateLiteralNode("VDS.RDF.Storage.VirtuosoManager, dotNetRDF.Data.Virtuoso"); //Serialize Configuration ConfigurationSerializationContext context = new ConfigurationSerializationContext(g); manager.SerializeConfiguration(context); Console.WriteLine("Serialized Configuration"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); //Ensure that it was serialized INode factory = g.GetTriplesWithPredicateObject(rdfType, objFactory).Select(t => t.Subject).FirstOrDefault(); Assert.IsNotNull(factory, "Should be an object factory in the serialized configuration"); Assert.IsTrue(g.ContainsTriple(new Triple(factory, dnrType, virtFactory)), "Should contain a Triple declaring the dnr:type to be the Virtuoso Object factory type"); INode objNode = g.GetTriplesWithPredicateObject(rdfType, genericManager).Select(t => t.Subject).FirstOrDefault(); Assert.IsNotNull(objNode, "Should be a generic manager in the serialized configuration"); Assert.IsTrue(g.ContainsTriple(new Triple(objNode, dnrType, virtManager)), "Should contain a Triple declaring the dnr:type to be the Virtuoso Manager type"); //Serialize again manager.SerializeConfiguration(context); Console.WriteLine("Serialized Configuration (after 2nd pass)"); foreach (Triple t in g.Triples) { Console.WriteLine(t.ToString(formatter)); } Console.WriteLine(); //Ensure that object factory has not been serialized again Assert.AreEqual(1, g.GetTriplesWithPredicateObject(rdfType, objFactory).Count(), "Should only be 1 Object Factory registered even after a 2nd serializer pass"); //Now try to load the object ConfigurationLoader.AutoConfigureObjectFactories(g); Object loadedObj = ConfigurationLoader.LoadObject(g, objNode); if (loadedObj is VirtuosoManager) { Assert.AreEqual(manager.ToString(), loadedObj.ToString(), "String forms should be equal"); } else { Assert.Fail("Returned an object of type '" + loadedObj.GetType().FullName + "' when deserializing"); } } finally { if (manager != null) { manager.Dispose(); } } }