这是我第一次看RDF,在尝试之后,我不知道如何解析它。我正在查看AFF4文件系统中使用的一些RDF (以Turtle格式),下面是其中的一部分:
<aff4://0295fab8-94b7-4435-bdb3-932cf48e40bd>
a aff4:ImageStream ;
aff4:chunkSize "32768"^^xsd:int ;
aff4:chunksInSegment "2048"^^xsd:int ;
aff4:compressionMethod <http://code.google.com/p/snappy/> ;
aff4:imageStreamHash "82798a275176aa141a2993ca8931535b1303545a0954473f5c5e55b4d8d5a8e3ebdb9e9323e5ecfaf65f8d379a8e2b9150750f5cf44851cf4edb6a2e05372f42"^^aff4:SHA512 ;
aff4:imageStreamIndexHash "039eb2da046cfb8c8d40e6f9b42aae501fb36f9b09b5f29d660d3637f87c37c98c3ee3b995265adff1d2b971fa795317333bf50200e72fdfe9fa96acdb88b6d0"^^aff4:SHA512 ;
aff4:size "185335808"^^xsd:long ;
aff4:stored : ;
aff4:target <aff4://92015053-5f7b-4e5a-a1e7-901d8943cf1f> ;
aff4:version "1"^^xsd:int .文件中有很多这样的东西,但我不知道如何访问其中的任何东西,到目前为止,我已经拼凑在一起:
private static void ParseInformationStream(Stream informationStream)
{
Console.WriteLine("Parsing information.turtle file: ");
informationStream.Position = 0;
TurtleParser turtleParser = new TurtleParser();
Graph graph = new Graph();
turtleParser.Load(graph, new StreamReader(informationStream));
foreach (var triple in graph.Triples)
{
Console.WriteLine(triple.Subject);
}
}这会打印出一些数据,但是如果我想访问aff4 4:压缩方法(节点?)具体来说,我该怎么做呢?我一直在读关于斯派克的书,但我需要的东西似乎有点过分了。
如有任何意见或建议,将不胜感激。
发布于 2018-10-04 15:32:10
您可以使用IGraph接口的方法来访问解析图的内容。例如,以下内容将检索所有映像流(在Turtle中,"a“是rdf:type谓词的快捷方式),并输出每个流的压缩方法:
// Get the node for rdf:type
var rdfType = graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
// Get the node for the aff4:ImageStream type
var imageStream = graph.GetUriNode("aff4:ImageStream");
// Get the node for the aff4:compressionMethod predicate
var compressionMethod = graph.CreateUriNode("aff4:compressionMethod");
// Get the streams (the subject of x a aff4:ImageStream in the Turtle)
var imageStreams = graph.GetTriplesWithPredicateObject(rdfType, imageStream).Select(t => t.Subject);
foreach (var streamInstance in imageStreams)
{
// Get the first compressionMethod value for the stream instance
var compression = graph.GetTriplesWithSubjectPredicate(streamInstance, compressionMethod)
.Select(t => t.Object).FirstOrDefault();
Console.WriteLine("Stream " + streamInstance + " uses compression method " + compression);
}有关访问dotNetRDF图中的节点的更多信息,请参见https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Working-With-Graphs。
https://stackoverflow.com/questions/52647830
复制相似问题