本文整理汇总了C#中VDS.RDF.Graph.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.Equals方法的具体用法?C# Graph.Equals怎么用?C# Graph.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VDS.RDF.Graph
的用法示例。
在下文中一共展示了Graph.Equals方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareTripleCollections
private static void CompareTripleCollections(BaseTripleCollection actualTriples, BaseTripleCollection expectedTriples, bool reduced)
{
var actualGraph = new Graph(actualTriples);
var expectedGraph = new Graph(expectedTriples);
Assert.IsTrue(expectedGraph.Equals(actualGraph), "Result graphs do not match.r\nExpected:\r\n{0}\r\nActual:\r\n{1}",
String.Join(",", expectedTriples.Select(t => t.ToString())),
String.Join(",", actualTriples.Select(t => t.ToString())));
}
示例2: GraphEquality
public void GraphEquality() {
try
{
Console.WriteLine("Going to get two copies of a Graph from DBPedia and compare");
Console.WriteLine("Using the DBPedia Graph for Barack Obama");
Graph g = new Graph();
Graph h = new Graph();
Uri target = new Uri("http://dbpedia.org/resource/Barack_Obama");
VDS.RDF.Parsing.UriLoader.Load(g, target);
Console.WriteLine("Loaded first copy OK - " + g.Triples.Count + " Triples");
VDS.RDF.Parsing.UriLoader.Load(h, target);
Console.WriteLine("Loaded second copy OK - " + h.Triples.Count + " Triples");
//Should have same Base Uri
Assert.AreEqual(g.BaseUri, h.BaseUri, "Should have the same Base URI after being loaded from the same URI via the URILoader");
//Do equality check
Console.WriteLine("Checking the Equality of the Graphs");
//TestTools.CompareGraphs(g, h, true);
Dictionary<INode, INode> mapping;
bool equals = g.Equals(h, out mapping);
Assert.IsTrue(equals, "Graphs should have been equal");
if (mapping != null)
{
Console.WriteLine("Blank Node Mapping was:");
foreach (KeyValuePair<INode, INode> pair in mapping)
{
Console.WriteLine(pair.Key.ToString() + " => " + pair.Value.ToString());
}
}
Console.WriteLine();
//Get a third graph of something different
Console.WriteLine("Going to get a third Graph of something different and check it is non-equal");
Uri target2 = new Uri("http://dbpedia.org/resource/Nottingham");
Graph i = new Graph();
VDS.RDF.Parsing.UriLoader.Load(i, target2);
//Should have different Base URIs and be non-equal
Assert.AreNotEqual(g.BaseUri, i.BaseUri, "Graphs retrieved from different URIs via the URILoader should have different Base URIs");
Assert.AreNotEqual(h.BaseUri, i.BaseUri, "Graphs retrieved from different URIs via the URILoader should have different Base URIs");
Assert.IsFalse(g.Equals(i));
Assert.IsFalse(h.Equals(i));
//TestTools.CompareGraphs(g, i, false);
//TestTools.CompareGraphs(h, i, false);
}
catch (WebException webEx)
{
TestTools.ReportError("Web Exception", webEx, false);
Console.WriteLine();
Console.WriteLine("Unable to retrieve the Graphs from the Web successfully!");
Assert.Inconclusive();
}
catch (RdfParseException parseEx)
{
TestTools.ReportError("Parsing Exception", parseEx, true);
}
catch (Exception ex)
{
TestTools.ReportError("Other Error", ex, true);
}
}
示例3: GraphWithBNodeEquality
public void GraphWithBNodeEquality()
{
try
{
Console.WriteLine("Testing Graph Equality when the Graphs have Blank Nodes");
Graph g = new Graph();
Graph h = new Graph();
TurtleParser ttlparser = new TurtleParser();
ttlparser.Load(g, "MergePart1.ttl");
ttlparser.Load(h, "MergePart1.ttl");
Assert.AreEqual(g.BaseUri, h.BaseUri, "The Base URIs of the Graphs should not be affected by the Load and so should be both null");
//TestTools.CompareGraphs(g, h, true);
Dictionary<INode, INode> mapping;
bool equals = g.Equals(h, out mapping);
Assert.IsTrue(equals, "Graphs should have been equal");
if (mapping != null)
{
Console.WriteLine("Blank Node Mapping was:");
foreach (KeyValuePair<INode, INode> pair in mapping)
{
Console.WriteLine(pair.Key.ToString() + " => " + pair.Value.ToString());
}
}
}
catch (RdfParseException parseEx)
{
TestTools.ReportError("Parsing Exception", parseEx, true);
}
catch (Exception ex)
{
TestTools.ReportError("Other Error", ex, true);
}
}
示例4: ParsingBlankNodeIDs
//.........这里部分代码省略.........
Console.WriteLine("Tests Blank Node ID assignment in Parsing and Serialization as well as Graph Equality");
Console.WriteLine();
List<IRdfWriter> writers = new List<IRdfWriter>() {
new NTriplesWriter(),
new TurtleWriter(),
new CompressingTurtleWriter(),
new Notation3Writer(),
new RdfXmlWriter(),
new FastRdfXmlWriter(),
new RdfJsonWriter()
};
List<IRdfReader> readers = new List<IRdfReader>() {
new NTriplesParser(),
new TurtleParser(),
new TurtleParser(),
new Notation3Parser(),
new RdfXmlParser(),
new RdfXmlParser(),
new RdfJsonParser()
};
foreach (IRdfReader parser in parsersToTest)
{
Console.WriteLine("Testing " + parser.GetType().ToString());
//parser.TraceTokeniser = true;
//parser.TraceParsing = true;
int s = 0;
foreach (String sample in samples)
{
Console.WriteLine();
Console.WriteLine("Sample:");
Console.WriteLine(sample);
Console.WriteLine();
Graph g = new Graph();
VDS.RDF.Parsing.StringParser.Parse(g, sample, parser);
Console.WriteLine("Original Graph");
Console.WriteLine(g.Triples.Count + " Triples produced");
foreach (Triple t in g.Triples)
{
Console.WriteLine(t.ToString());
}
Console.WriteLine();
Assert.AreEqual(expectedTriples[s], g.Triples.Count, "Should have produced " + expectedTriples[s] + " Triples");
Assert.AreEqual(expectedSubjects[s], g.Triples.SubjectNodes.Distinct().Count(), "Should have produced " + expectedSubjects[s] + " distinct subjects");
//Try outputting with each of the available writers
for (int i = 0; i < writers.Count; i++)
{
String temp = StringWriter.Write(g, writers[i]);
Graph h = new Graph();
VDS.RDF.Parsing.StringParser.Parse(h, temp, readers[i]);
Console.WriteLine("Trying " + writers[i].GetType().ToString());
Console.WriteLine("Graph after Serialization and Parsing");
Console.WriteLine(h.Triples.Count + " Triples produced");
foreach (Triple t in h.Triples)
{
Console.WriteLine(t.ToString());
}
Console.WriteLine();
if (expectedTriples[s] != h.Triples.Count || expectedSubjects[s] != h.Triples.SubjectNodes.Distinct().Count())
{
Console.WriteLine(writers[i].GetType().ToString() + " failed");
Console.WriteLine(temp);
}
Assert.AreEqual(expectedTriples[s], h.Triples.Count, "Should have produced " + expectedTriples[s] + " Triples");
Assert.AreEqual(expectedSubjects[s], h.Triples.SubjectNodes.Distinct().Count(), "Should have produced " + expectedSubjects[s] + " distinct subjects");
//Do full equality Test
Dictionary<INode, INode> mapping;
bool equals = g.Equals(h, out mapping);
if (!equals)
{
Console.WriteLine(writers[i].GetType().ToString() + " failed");
Console.WriteLine(temp);
}
Assert.IsTrue(equals, "Graphs should be equal");
Console.WriteLine("Node Mapping was:");
foreach (KeyValuePair<INode, INode> pair in mapping)
{
Console.WriteLine(pair.Key.ToString() + " => " + pair.Value.ToString());
}
Console.WriteLine();
}
Console.WriteLine("All writers OK");
s++;
}
Console.WriteLine();
Console.WriteLine();
}
}
示例5: ParsingCollections
public void ParsingCollections()
{
List<IRdfReader> parsersToTest = new List<IRdfReader>()
{
new TurtleParser(),
new Notation3Parser()
};
String[] samples = new String[] {
"@prefix ex: <http://example.com/>. (\"one\" \"two\") a ex:Collection .",
"@prefix ex: <http://example.com/>. (\"one\" \"two\" \"three\") a ex:Collection .",
"@prefix ex: <http://example.com/>. (1) ex:someProp \"Value\"."
};
int[] expectedTriples = new int[] {
5,
7,
3
};
int[] expectedSubjects = new int[] {
2,
3,
1
};
List<IRdfWriter> writers = new List<IRdfWriter>() {
new NTriplesWriter(),
new TurtleWriter(),
new CompressingTurtleWriter(),
new Notation3Writer(),
new RdfXmlWriter(),
new FastRdfXmlWriter(),
new RdfJsonWriter()
};
List<IRdfReader> readers = new List<IRdfReader>() {
new NTriplesParser(),
new TurtleParser(),
new TurtleParser(),
new Notation3Parser(),
new RdfXmlParser(),
new RdfXmlParser(),
new RdfJsonParser()
};
foreach (IRdfReader parser in parsersToTest)
{
Console.WriteLine("Testing " + parser.GetType().ToString());
//parser.TraceTokeniser = true;
//parser.TraceParsing = true;
int s = 0;
foreach (String sample in samples)
{
Console.WriteLine();
Console.WriteLine("Sample:");
Console.WriteLine(sample);
Console.WriteLine();
Graph g = new Graph();
VDS.RDF.Parsing.StringParser.Parse(g, sample, parser);
Console.WriteLine(g.Triples.Count + " Triples produced");
foreach (Triple t in g.Triples)
{
Console.WriteLine(t.ToString());
}
Assert.AreEqual(expectedTriples[s], g.Triples.Count, "Should have produced " + expectedTriples[s] + " Triples");
Assert.AreEqual(expectedSubjects[s], g.Triples.SubjectNodes.Distinct().Count(), "Should have produced " + expectedSubjects[s] + " distinct subjects");
//Try outputting with each of the available writers
for (int i = 0; i < writers.Count; i++)
{
String temp = StringWriter.Write(g, writers[i]);
Graph h = new Graph();
VDS.RDF.Parsing.StringParser.Parse(h, temp, readers[i]);
Console.WriteLine("Trying " + writers[i].GetType().ToString());
Assert.AreEqual(expectedTriples[s], h.Triples.Count, "Should have produced " + expectedTriples[s] + " Triples");
Assert.AreEqual(expectedSubjects[s], h.Triples.SubjectNodes.Distinct().Count(), "Should have produced " + expectedSubjects[s] + " distinct subjects");
Dictionary<INode, INode> mapping;
bool equals = g.Equals(h, out mapping);
Assert.IsTrue(equals, "Graphs should have been equal");
Console.WriteLine("Node mapping was:");
foreach (KeyValuePair<INode, INode> pair in mapping)
{
Console.WriteLine(pair.Key.ToString() + " => " + pair.Value.ToString());
}
Console.WriteLine();
}
Console.WriteLine("All writers OK");
s++;
}
Console.WriteLine();
Console.WriteLine();
}
}
示例6: TestWriter
public static void TestWriter(StreamWriter output, Graph g, IRdfWriter writer, IRdfReader reader, String file)
{
Stopwatch timer = new Stopwatch();
Console.WriteLine();
Console.WriteLine(new String('-', file.Length));
Console.WriteLine(file);
Console.WriteLine("Attempting serialization with " + writer.GetType().ToString());
//Show Compression Level
if (writer is ICompressingWriter)
{
Console.WriteLine("Compression Level is " + ((ICompressingWriter)writer).CompressionLevel);
}
//Enable Pretty Printing if supported
if (writer is IPrettyPrintingWriter)
{
((IPrettyPrintingWriter)writer).PrettyPrintMode = true;
}
try
{
timer.Start();
writer.Save(g, "writer_tests/" + file + ".out");
Console.WriteLine("Serialization Done");
}
catch (IOException ioEx)
{
reportError(output, "IO Exception", ioEx);
}
catch (RdfParseException parseEx)
{
reportError(output, "Parsing Exception", parseEx);
}
catch (RdfException rdfEx)
{
reportError(output, "RDF Exception", rdfEx);
}
catch (Exception ex)
{
reportError(output, "Other Exception", ex);
}
finally
{
timer.Stop();
Console.WriteLine("Writing took " + timer.ElapsedMilliseconds + "ms");
//Get the relevant Reader
Graph h = new Graph();
try
{
//Read back in the serialized output to check it's valid RDF
Console.WriteLine("Attempting to read back in from serialized Output using " + reader.GetType().ToString());
reader.Load(h, "writer_tests/" + file + ".out");
Console.WriteLine("Serialized Output was valid RDF");
//Check same number of Triples are present
if (g.Triples.Count == h.Triples.Count)
{
Console.WriteLine("Correct number of Triples loaded");
}
else
{
throw new RdfException("Incorrect number of Triples loaded, got " + h.Triples.Count + " but expected " + g.Triples.Count);
}
//Check same number of Subjects are present
if (g.Triples.SubjectNodes.Distinct().Count() == h.Triples.SubjectNodes.Distinct().Count())
{
Console.WriteLine("Correct number of Subjects loaded");
}
else
{
throw new RdfException("Incorrect number of Subjects loaded, got " + h.Triples.SubjectNodes.Distinct().Count() + " but expected " + g.Triples.SubjectNodes.Distinct().Count());
}
//Reserialize to NTriples
NTriplesWriter ntwriter = new NTriplesWriter();
ntwriter.SortTriples = true;
ntwriter.Save(h, "writer_tests/" + file + ".nt");
Console.WriteLine("Serialized Output reserialized to NTriples");
//Check Graphs are Equal
if (g.Equals(h))
{
Console.WriteLine("Graphs are Equal");
}
else
{
Console.WriteLine("First Graphs triples:");
foreach (Triple t in g.Triples)
{
Console.WriteLine(t.ToString());
}
Console.WriteLine();
Console.WriteLine("Second Graph triples:");
foreach (Triple t in h.Triples)
{
Console.WriteLine(t.ToString());
//.........这里部分代码省略.........