本文整理汇总了C#中VDS.RDF.Graph.GetUriNode方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.GetUriNode方法的具体用法?C# Graph.GetUriNode怎么用?C# Graph.GetUriNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VDS.RDF.Graph
的用法示例。
在下文中一共展示了Graph.GetUriNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
StreamWriter output = new StreamWriter("ConfigurationLoaderTests.txt");
Console.SetOut(output);
Console.WriteLine("## Configuration Loader Tests");
Console.WriteLine();
try
{
Console.WriteLine("Attempting to load our sample configuration graph");
Graph g = new Graph();
FileLoader.Load(g, "sample-config.ttl");
Console.WriteLine("Sample graph loaded OK");
Console.WriteLine();
//Test AppSettings resolution
Console.WriteLine("# Testing <appSetting:Key> URI resolution");
//Get the Actual Values
String actualStr = ConfigurationManager.AppSettings["TestString"];
bool actualTrue = Boolean.Parse(ConfigurationManager.AppSettings["TestTrue"]);
bool actualFalse = Boolean.Parse(ConfigurationManager.AppSettings["TestFalse"]);
int actualInt = Int32.Parse(ConfigurationManager.AppSettings["TestInt32"]);
Console.WriteLine("Actual String: " + actualStr);
Console.WriteLine("Actual True: " + actualTrue);
Console.WriteLine("Actual False: " + actualFalse);
Console.WriteLine("Actual Int: " + actualInt);
//Now load the resolved values
IUriNode objNode = g.GetUriNode(new Uri("dotnetrdf:test"));
String resolvedStr = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:stylesheet"));
String resolvedStr2 = ConfigurationLoader.GetConfigurationValue(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:stylesheet"));
bool resolvedTrue = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:cacheSliding"), false);
bool resolvedFalse = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:showErrors"), true);
int resolvedInt = ConfigurationLoader.GetConfigurationInt32(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, "dnr:cacheDuration"), -1);
Console.WriteLine("Resolved String: " + resolvedStr);
Console.WriteLine("Resolved True: " + resolvedTrue);
Console.WriteLine("Resolved False: " + resolvedFalse);
Console.WriteLine("Resolved Int: " + resolvedInt);
if (actualStr != resolvedStr) Console.WriteLine("AppSetting resolution failed");
if (actualStr != resolvedStr2) Console.WriteLine("AppSetting resolution failed");
if (resolvedStr != resolvedStr2) Console.WriteLine("AppSetting resolution failed");
if (!resolvedTrue) Console.WriteLine("AppSetting resolution failed");
if (actualTrue != resolvedTrue) Console.WriteLine("AppSetting resolution failed");
if (resolvedFalse) Console.WriteLine("AppSetting resolution failed");
if (actualFalse != resolvedFalse) Console.WriteLine("AppSetting resolution failed");
if (actualInt != resolvedInt) Console.WriteLine("AppSetting resolution failed");
//Attempt to load our MicrosoftSqlStoreManager from the Graph
Console.WriteLine("# Attempting to load an object based on the Configuration Graph");
INode testObj = g.GetUriNode(new Uri("dotnetrdf:sparqlDB"));
if (testObj == null) throw new RdfException("Couldn't find the expected Test Object Node in the Graph");
Object loaded = ConfigurationLoader.LoadObject(g, testObj);
Console.WriteLine("Loaded an object, now need to check if it's of the type we expected...");
if (loaded is ISqlIOManager)
{
Console.WriteLine("It's an ISqlIOManager, is it for Microsoft SQL Server...");
if (loaded is MicrosoftSqlStoreManager)
{
Console.WriteLine("Success - Object loaded to correct type OK");
}
else
{
Console.WriteLine("Failure - Object loaded as " + loaded.GetType().ToString());
}
}
else
{
Console.WriteLine("Failure - Object loaded as " + loaded.GetType().ToString());
}
Console.WriteLine();
//Attempt to load it as a type for which there aren't any loaders defined
ConfigurationLoader.ClearCache();
Console.WriteLine("# Attempting to load the same object as a type for which there is no loader");
try
{
loaded = ConfigurationLoader.LoadObject(g, testObj, typeof(Triple));
Console.WriteLine("Failure - Loaded even though a bad type was provided");
}
catch (DotNetRdfConfigurationException configEx)
{
Console.WriteLine("Success - Produced an error since there was no loader for the type provided:");
Console.WriteLine(configEx.Message);
}
Console.WriteLine();
ConfigurationLoader.ClearCache();
//Attempt to load a Graph from the Configuration
Console.WriteLine("# Attempting to load a Graph which is defined in our configuration");
testObj = g.GetBlankNode("a");
ConfigurationLoaderTests.LoadGraphTest(g, testObj);
Console.WriteLine("# Attempting to load another Graph which is defined in our configuration");
testObj = g.GetBlankNode("b");
//.........这里部分代码省略.........
示例2: CompareResultGraphs
private void CompareResultGraphs(string results, string expectedResultsPath, bool reduced)
{
var expectedResultGraph = new Graph();
FileLoader.Load(expectedResultGraph, expectedResultsPath);
var resultSet = expectedResultGraph.GetUriNode(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet"));
if (resultSet != null)
{
var rdfParser = new SparqlRdfParser();
var xmlParser = new SparqlXmlParser();
var actualResultSet = new SparqlResultSet();
var expectedResultSet = new SparqlResultSet();
using (var tr = new StringReader(results))
{
xmlParser.Load(actualResultSet, tr);
}
rdfParser.Load(expectedResultSet, expectedResultsPath);
var bnodeMap = new Dictionary<string, string>();
CompareSparqlResults(actualResultSet, expectedResultSet, reduced, bnodeMap);
}
else
{
// This is a constructed graph
var actualGraph = new Graph();
actualGraph.LoadFromString(results);
CompareTripleCollections(actualGraph.Triples, expectedResultGraph.Triples, reduced);
}
}
示例3: CompareResultGraphs
private void CompareResultGraphs(string results, string expectedResultsPath, bool reduced)
{
var expectedResultGraph = new Graph();
FileLoader.Load(expectedResultGraph, expectedResultsPath);
var resultSet = expectedResultGraph.GetUriNode(new Uri("http://www.w3.org/2001/sw/DataAccess/tests/result-set#ResultSet"));
if (resultSet != null)
{
var rdfParser = new SparqlRdfParser();
var xmlParser = new SparqlXmlParser();
var actualResultSet = new SparqlResultSet();
var expectedResultSet = new SparqlResultSet();
using (var tr = new StringReader(results))
{
xmlParser.Load(actualResultSet, tr);
}
rdfParser.Load(expectedResultSet, expectedResultsPath);
var bnodeMap = new Dictionary<string, string>();
CompareSparqlResults(actualResultSet, expectedResultSet, reduced, bnodeMap);
}
else
{
// This is a constructed graph
var actualGraph = new Graph();
actualGraph.LoadFromString(results);
var toReplace = actualGraph.Triples.Where(
t => IsGenid(t.Subject) || IsGenid(t.Predicate) || IsGenid(t.Object)).ToList();
foreach (var t in toReplace)
{
var mapped = MapGenidToBlank(t);
actualGraph.Retract(t);
actualGraph.Assert(mapped);
}
CompareTripleCollections(actualGraph.Triples, expectedResultGraph.Triples, reduced);
}
}