Class Triple
Class for representing RDF Triples in memory.
Inheritance
Implements
Inherited Members
Namespace: VDS.RDF
Assembly: dotNetRdf.dll
Syntax
public sealed class Triple : IComparable<Triple>
Constructors
| Improve this Doc View SourceTriple(INode, INode, INode, IGraph)
Constructs a Triple from Nodes that belong to the same Graph/Node Factory and associates this Triple with the given Graph (doesn't assert the Triple).
Declaration
[Obsolete("This constructor is obsolete and will be removed in a future version.")]
public Triple(INode subj, INode pred, INode obj, IGraph g)
Parameters
Type | Name | Description |
---|---|---|
INode | subj | Subject. |
INode | pred | Predicate. |
INode | obj | Object. |
IGraph | g | Graph. |
Remarks
Will throw an RdfException if the Nodes don't belong to the same Graph/Node Factory.
Exceptions
Type | Condition |
---|---|
RdfException | Thrown if the Nodes aren't all from the same Graph/Node Factory. |
Triple(INode, INode, INode, ITripleContext)
Constructs a Triple from Nodes that belong to the same Graph/Node Factory with some Context.
Declaration
public Triple(INode subj, INode pred, INode obj, ITripleContext context)
Parameters
Type | Name | Description |
---|---|---|
INode | subj | Subject of the Triple. |
INode | pred | Predicate of the Triple. |
INode | obj | Object of the Triple. |
ITripleContext | context | Context Information for the Triple. |
Remarks
Will throw an RdfException if the Nodes don't belong to the same Graph/Node Factory.
Exceptions
Type | Condition |
---|---|
RdfException | Thrown if the Nodes aren't all from the same Graph/Node Factory. |
Triple(INode, INode, INode)
Constructs a Triple from Nodes that belong to the same Graph/Node Factory.
Declaration
public Triple(INode subj, INode pred, INode obj)
Parameters
Type | Name | Description |
---|---|---|
INode | subj | Subject of the Triple. |
INode | pred | Predicate of the Triple. |
INode | obj | Object of the Triple. |
Remarks
Will throw an RdfException if the Nodes don't belong to the same Graph/Node Factory.
Exceptions
Type | Condition |
---|---|
RdfException | Thrown if the Nodes aren't all from the same Graph/Node Factory. |
Properties
| Improve this Doc View SourceContext
Gets the Context Information for this Triple.
Declaration
public ITripleContext Context { get; set; }
Property Value
Type | Description |
---|---|
ITripleContext |
Remarks
Context may be null where no Context for the Triple has been defined.
IsGroundTriple
Gets whether the Triple is a Ground Triple.
Declaration
public bool IsGroundTriple { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
A Ground Triple is any Triple considered to state a single fixed fact. In practice this means that the Triple does not contain any Blank Nodes, and does not quote any triples containing blank nodes.
Nodes
Gets an enumeration of the Nodes in the Triple.
Declaration
public IEnumerable<INode> Nodes { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><INode> |
Remarks
Returned as subject, predicate, object.
Object
Gets the Object of the Triple.
Declaration
public INode Object { get; }
Property Value
Type | Description |
---|---|
INode |
Predicate
Gets the Predicate of the Triple.
Declaration
public INode Predicate { get; }
Property Value
Type | Description |
---|---|
INode |
Subject
Gets the Subject of the Triple.
Declaration
public INode Subject { get; }
Property Value
Type | Description |
---|---|
INode |
Methods
| Improve this Doc View SourceCompareTo(Triple)
Implementation of CompareTo for Triples which allows Triples to be sorted.
Declaration
public int CompareTo(Triple other)
Parameters
Type | Name | Description |
---|---|---|
Triple | other | Triple to compare to. |
Returns
Type | Description |
---|---|
int |
Remarks
Triples are Ordered by Subjects, Predicates and then Objects. Triples are only partially orderable since the CompareTo methods on Nodes only define a partial ordering over Nodes.
Equals(object)
Implementation of Equality for Triples.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | Object to compare with. |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Remarks
Triples are considered equal on the basis of two things:.
- The Hash Codes of the Triples are identical
- The logical conjunction (AND) of the equality of the Subject, Predicate and Object is true. Each pair of Nodes must either be Equal using Node Equality or are both Blank Nodes and have identical Node IDs (i.e. are indistinguishable for equality purposes on a single Triple level)
GetHashCode()
Implementation of Hash Codes for Triples.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
Remarks
Returns the Hash Code of the Triple which is calculated as the Hash Code of the String formed by concatenating the Hash Codes of its constituent Nodes. This Hash Code is precomputed in the Constructor of a Triple since it will be used a lot (in Triple Equality calculation, Triple Collections etc).
Since Hash Codes are based on a String representation there is no guarantee of uniqueness though the same Triple will always give the same Hash Code (on a given Platform - see the MSDN Documentation for string.GetHashCode() for further details).
HasObject(INode)
Indicates whether the Triple has the given Node as the Object.
Declaration
public bool HasObject(INode n)
Parameters
Type | Name | Description |
---|---|---|
INode | n | Node to test upon. |
Returns
Type | Description |
---|---|
System.Boolean |
HasPredicate(INode)
Indicates whether the Triple has the given Node as the Predicate.
Declaration
public bool HasPredicate(INode n)
Parameters
Type | Name | Description |
---|---|---|
INode | n | Node to test upon. |
Returns
Type | Description |
---|---|
System.Boolean |
HasSubject(INode)
Indicates whether the Triple has the given Node as the Subject.
Declaration
public bool HasSubject(INode n)
Parameters
Type | Name | Description |
---|---|---|
INode | n | Node to test upon. |
Returns
Type | Description |
---|---|
System.Boolean |
Involves(Uri)
Checks whether the Triple involves a given Uri.
Declaration
public bool Involves(Uri uri)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | uri | The Uri to test upon. |
Returns
Type | Description |
---|---|
System.Boolean | True if the Triple has a UriNode with the given Uri. |
Involves(INode)
Checks whether the Triple involves a given Node.
Declaration
public bool Involves(INode n)
Parameters
Type | Name | Description |
---|---|---|
INode | n | The Node to test upon. |
Returns
Type | Description |
---|---|
System.Boolean | True if the Triple contains the given node or quotes a triple that involves the given node. |
ToString()
Gets a String representation of a Triple in the form 'Subject , Predicate , Object'.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |
Overrides
ToString(bool)
Gets a String representation of a Triple in the form 'Subject , Predicate , Object' with optional compression of URIs to QNames.
Declaration
[Obsolete("This method is obsolete and will be removed in a future version. Use ToString() or ToString(ITripleFormatter) instead.")]
public string ToString(bool compress)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | compress | Controls whether URIs will be compressed to QNames in the String representation. |
Returns
Type | Description |
---|---|
string |
Remarks
As of dotNetRdf 3.0, this method is obsolete and does not perform an URI to QName compression. To produce a compressed string, use the ToString(ITripleFormatter) overload passing in a formatter configured with the desired INamespaceMapper.
ToString(ITripleFormatter)
Gets the String representation of a Triple using the given Triple Formatter.
Declaration
public string ToString(ITripleFormatter formatter)
Parameters
Type | Name | Description |
---|---|---|
ITripleFormatter | formatter | Formatter. |
Returns
Type | Description |
---|---|
string |