4 public struct Statement
{
10 public static Entity DefaultMeta
= new Entity(null);
12 public Statement(Entity subject
, Entity predicate
, Resource
@object)
13 : this(subject
, predicate
, @object, DefaultMeta
) {
16 public Statement(Entity subject
, Entity predicate
, Resource
@object, Entity meta
) {
23 public Entity Subject { get { return s; }
}
24 public Entity Predicate { get { return p; }
}
25 public Resource Object { get { return o; }
}
27 public Entity Meta { get { return m; }
}
29 internal bool AnyNull
{
31 return Subject
== null || Predicate
== null || Object
== null || Meta
== null;
35 public Statement
Invert() {
36 if (!(Object
is Entity
)) throw new ArgumentException("The object of the statement must be an entity.");
37 return new Statement((Entity
)Object
, Predicate
, Subject
, Meta
);
40 public bool Matches(Statement statement
) {
41 if (Subject
!= null && Subject
!= statement
.Subject
) return false;
42 if (Predicate
!= null && Predicate
!= statement
.Predicate
) return false;
43 if (Object
!= null && Object
!= statement
.Object
) return false;
44 if (Meta
!= null && Meta
!= statement
.Meta
) return false;
48 public override string ToString() {
50 if (Subject
!= null) ret
+= "<" + Subject
+ "> "; else ret
+= "? ";
51 if (Predicate
!= null) ret
+= "<" + Predicate
+ "> "; else ret
+= "? ";
53 if (Object
is Literal
)
56 ret
+= "<" + Object
+ ">";
60 if (Meta
!= null && Meta
!= DefaultMeta
) ret
+= " meta=<" + Meta
+ ">";
64 public override bool Equals(object other
) {
65 return (Statement
)other
== this;
68 public override int GetHashCode() {
70 if (s
!= null) ret
= unchecked(ret
+ s
.GetHashCode());
71 if (p
!= null) ret
= unchecked(ret
+ p
.GetHashCode());
72 if (o
!= null) ret
= unchecked(ret
+ o
.GetHashCode());
73 if (m
!= null) ret
= unchecked(ret
+ m
.GetHashCode());
77 public static bool operator ==(Statement a
, Statement b
) {
78 if ((a
.Subject
== null) != (b
.Subject
== null)) return false;
79 if ((a
.Predicate
== null) != (b
.Predicate
== null)) return false;
80 if ((a
.Object
== null) != (b
.Object
== null)) return false;
81 if ((a
.Meta
== null) != (b
.Meta
== null)) return false;
82 if (a
.Subject
!= null && !a
.Subject
.Equals(b
.Subject
)) return false;
83 if (a
.Predicate
!= null && !a
.Predicate
.Equals(b
.Predicate
)) return false;
84 if (a
.Object
!= null && !a
.Object
.Equals(b
.Object
)) return false;
85 if (a
.Meta
!= null && !a
.Meta
.Equals(b
.Meta
)) return false;
88 public static bool operator !=(Statement a
, Statement b
) {
93 public struct SelectPartialFilter
{
97 public static readonly SelectPartialFilter All
= new SelectPartialFilter(true, true, true, true);
99 public SelectPartialFilter(bool subject
, bool predicate
, bool @object, bool meta
) {
108 public bool Subject { get { return s; }
}
109 public bool Predicate { get { return p; }
}
110 public bool Object { get { return o; }
}
111 public bool Meta { get { return m; }
}
113 public bool SelectAll { get { return s && p && o && m; }
}
114 public bool SelectNone { get { return !s && !p && !o && !m; }
}
116 public bool SelectFirst { get { return first; }
set { first = value; }
}
118 public override string ToString() {
119 if (SelectAll
) return "All";
120 if (SelectNone
) return "None";
122 if (Subject
) ret
+= "S";
123 if (Predicate
) ret
+= "P";
124 if (Object
) ret
+= "O";
125 if (Meta
) ret
+= "M";