SchemaWeb Directory
SchemaWeb Data Center
Home | Browse | Search | Query | Web Services | Submit a Schema | Contact | Login
VicSoft.Rdf Parser
[ RDF Meta ]
Introduction
The VicSoft.Rdf Parser is a .Net software component for processing RDF data. One or more RDF/XML documents can be loaded into the parser and then the resulting RDF graph can be queried using an easy to use object orientated interface. The VicSoft.Rdf Parser uses Jason Diamond's RdfXmlReader, upgraded to the latest RDF specifications, to extract the RDF triples from the RDF/XML file.
Licence
Creative Commons License
The VicSoft.Rdf Parser is licensed under a Creative Commons Licence. Please note that this is a ShareAlike licence. Any distribution after modification must be shared. If you are unable to comply, please contact VicSoft for a suitable licence.
[ RDF Licence ]
System Requirements
The VicSoft.Rdf Parser requires the .Net Framework 1.0. The parser binaries will run against the .Net Framework 1.1. Alternatively the source files can be recompiled with .Net 1.1 or the project can be upgraded with Visual Studio 2003. This RDF parser was developed on the Windows platform and although care was taken to ensure compatibility, it is un-tested with Mono.
Download
Download VicSoft.Rdf Parser 1.0 (build 1464) [Binaries]
Download VicSoft.Rdf Parser 1.0 (build 1464) [Source]
Getting Started
Binaries
Unzip the contents of the binaries zip file to a location on your hard disk.
To use the VicSoft.Rdf Parser, set a reference in your client project to VicSoft.Rdf.dll and VicSoft.Rdf.IRdfParser.dll in the VicSoft.Rdf_Binaries folder.
The binaries folder also contains two simple client applications to test the parser and demonstrate example usage:
TestParser.exe
TestParser.exe is a console application which reads an RDF/XML file and outputs the RDF triples. If the file is a FOAF file, then the application will find and iterate through the foaf:Person information.
Usage:
At the command prompt, navigate to the binaries directory and type TestParser <url> where <url> is the location of the RDF/XML file.
Example:
TestParser http://www.schemaweb.info/foaf/vlindesay.xml
RdfQuery.exe
RdfQuery.exe is a Windows Forms application which allows you to load one or more RDF/XML files into the parser and then to query the graph by subject, predicate and object.
Use * as a wildcard for subject, predicate and object parameters.
Source
Unzip the contents of the source zip file to a location on your hard disk.
To use the VicSoft.Rdf Parser, set a reference in your client project to VicSoft/Vicsoft.Rdf/bin/release/VicSoft.Rdf.dll and VicSoftf/Vicsoft.Rdf.IRdfParser/bin/release/VicSoft.Rdf.IRdfParser.dll.
Open either VicSoft/RdfQuery.sln or VicSoft/TestParser.sln in Visual Studio .Net to run the test applications and inspect the source code.
Support
Please post comments, bug reports and queries on the VicSoft.Rdf Forum.
Example Usage
The following code demonstrates usage of the parser using C#. Ready to cut and paste and go.
// Ensure that this namespace import appears at the top of your class file
using VicSoft.Rdf;

// Create a parser object. The RdfParser class implements the IRdfParser interface
IRdfParser parser = new RdfParser();

// Try my FOAF
string rdfPath = "http://www.schemaweb.info/foaf/vlindesay.xml";

// Or try the URL of this page to extract the RDF license (Parser.aspx is XHTML therefore will load into the parser)
// string rdfPath = "http://www.schemaweb.info/parser/Parser.aspx";

// Create a Uri object with the URL string
Uri rdfUri = new Uri(rdfPath);

// Load the parser with RDF/XML from the URL
parser.Load(rdfUri);
                
// Get all statements from the graph using the wildcard null for subject, predicate and object parameters
Statements statements = parser.GetStatements(null, null, null);

// Use a foreach loop to iterate through the statements collection and get the subject, predicate and object objects
foreach (Statement statement in statements)
{
    Subject subject = statement.Subject;
    Predicate predicate = statement.Predicate;
    VicSoft.Rdf.Object obj = statement.Object;
    
    string subjectValue = subject.Value;
    string subjectType = subject.Type;
    string predicateValue = predicate.Value; 
    string objectValue = obj.Value;
    string objectType = obj.Type;
    string objectDataType = obj.DataType;
    string objectLanguage = obj.Language;
    
    // Do something interesting with these values here 
}

// Serialise the whole graph into XML
string statementsXml = statements.Xml;

// Do something interesting with the XML - some XSLT perhaps?

// Find all URIs of type foaf:Person
Subjects people = parser.GetSubjects("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://xmlns.com/foaf/0.1/Person");                

// Use a foreach loop to iterate through the subjects collection
foreach (Subject person in people)
{
    // Get the collection of names for this person
    Objects nameObjects = parser.GetObjects(person.Value, "http://xmlns.com/foaf/0.1/name");
    // Get the first name object - Assume that a person has only one name
    VicSoft.Rdf.Object nameObject = nameObjects[0];
    // Get the person's name
    string name = nameObject.Value;

    // Do something useful with the name here
}

// Use a for loop with a counter to iterate through the subjects collection
for (int i = 0; i < people.Count; i++)
{
    // Get the person URI
    Subject person = people[i];
    // Get the collection of names for this person
    Objects nameObjects = parser.GetObjects(person.Value, "http://xmlns.com/foaf/0.1/name");
    // Get the first name object
    VicSoft.Rdf.Object nameObject = nameObjects[0];
    // Get the XML serialisation of this name object
    string xml = nameObject.Xml;

    // Do something useful with the XML here
}
API
VicSoft.Rdf.RdfParser
The parser object.
Constructor
public RdfParser ()
Initialises a new instance of the parser object.
Methods
public void Load ( System.Uri url )
Loads the parser with RDF/XML from a URL. This method will merge the new RDF with the existing graph.
Parameters:
url: The source URL of the RDF.
public void Load ( string rdf , System.Uri url )
Loads the parser with RDF/XML or triples XML. This method will merge the new RDF with the existing graph.
Parameters:
rdf: The RDF/XML or triples XML.
url: The source URL of the RDF.
public void Load ( string rdf )
Loads the parser with RDF/XML or triples XML. This method will merge the new RDF with the existing graph.
Parameters:
rdf: The RDF/XML or triples XML.
public void Clear ()
Clears the existing RDF graph loaded into the parser.
public VicSoft.Rdf.Statements GetStatements ( string subject , string predicate , string obj )
Gets the statements for a given subject, predicate and object. Null may be passed as a wildcard to subject, predicate and obj params. Pass null to all params to return all statements.
Parameters:
subject: The subject.
predicate: The predicate.
obj: The object.
Returns:
A Statements object.
public VicSoft.Rdf.Subjects GetSubjects ( string predicate , string obj )
Gets the subjects for a given predicate and object. Pass null to predicate param to query on object only. Pass null to obj param to query on predicate only. Pass null to both params to return all subjects.
Parameters:
predicate: The predicate.
obj: The object.
Returns:
A Subjects object.
public VicSoft.Rdf.Objects GetObjects ( string subject , string predicate )
Gets the objects for a given subject and predicate. Pass null to predicate param to query on subject only. Pass null to subject param to query on predicate only. Pass null to both params to return all objects.
Parameters:
subject: The subject.
predicate: The predicate.
Returns:
An Objects object.
public VicSoft.Rdf.Predicates GetPredicates ( string subject , string obj )
Gets the predicates for a given subject and object. Pass null to obj param to query on subject only. Pass null to subject param to query on object only. Pass null to both params to return all predicates.
Parameters:
subject: The subject.
obj: The object.
Returns:
A Predicates object.
public string GetSubjectValue ( string predicate , string obj )
Returns a subject value for a given predicate and object. Returns the value of the first subject found.
Parameters:
predicate: The predicate.
obj: The object.
Returns:
The subject value.
public string GetObjectValue ( string subject , string predicate )
Returns an object value for a given subject and predicate. Returns the value of the first object found.
Parameters:
subject: The subject.
predicate: The predicate.
Returns:
The object value.
public System.Boolean StatementExists ( string subject , string predicate , string obj )
Checks whether a statement exists. No parameter may be null for this method.
Parameters:
subject: The subject.
predicate: The predicate.
obj: The object.
Returns:
True or false.
VicSoft.Rdf.Statements
A collection of Statement objects.
Properties
public VicSoft.Rdf.Statement this [int i] [ get ]
The indexer for the Statements class.
public int Count [ get ]
The number of Statement objects in the collection.
public string Xml [ get ]
The Statements serialised as XML.
VicSoft.Rdf.Subjects
A collection of Subject objects.
Properties
public VicSoft.Rdf.Subject this [int i] [ get ]
The indexer for the Subjects class.
public int Count [ get ]
The number of Subject objects in the collection.
public string Xml [ get ]
The Subjects serialised as XML.
VicSoft.Rdf.Predicates
A collection of Predicate objects.
Properties
public VicSoft.Rdf.Predicate this [int i] [ get ]
The indexer for the Predicates class.
public int Count [ get ]
The number of Predicate objects in the collection.
public string Xml [ get ]
The Predicates serialised as XML.
VicSoft.Rdf.Objects
A collection of Object objects.
Properties
public VicSoft.Rdf.Object this [int i] [ get ]
The indexer for the Objects class.
public int Count [ get ]
The number of Object objects in the collection.
public string Xml [ get ]
The Objects serialised as XML.
VicSoft.Rdf.Statement
The Statement object contains an RDF triple.
Properties
public VicSoft.Rdf.Subject Subject [ get, set ]
The Subject object of a Statement.
public VicSoft.Rdf.Predicate Predicate [ get, set ]
The Predicate object of a Statement.
public VicSoft.Rdf.Object Object [ get, set ]
The Object object of a Statement.
public string Xml [ get ]
The Statement serialised as XML.
VicSoft.Rdf.Subject
The Subject object contains the subject of an RDF triple.
Properties
public string Value [ get, set ]
The value of the Subject object.
public string Type [ get, set ]
The type of the Subject object. Possible values are 'uri', 'anonymous' and 'blank'.
public string Xml [ get ]
The Subject serialised as XML.
VicSoft.Rdf.Predicate
The Predicate object contains the predicate of an RDF triple.
Properties
public string Value [ get, set ]
The value of the Predicate object.
public string Xml [ get ]
The Predicate serialised as XML.
VicSoft.Rdf.Object
The Object object contains the object of an RDF triple.
Properties
public string Value [ get, set ]
The value of the Object object.
public string Type [ get, set ]
The type of the Object object. Possible values are 'uri', 'anonymous', 'blank', 'literal' and 'xml'.
public string Language [ get, set ]
The language of the Object value. Applicable to 'literal' Objects only.
public string DataType [ get, set ]
The data-type of the Object value. Applicable to 'literal' Objects only.
public string Xml [ get ]
The Object serialised as XML.