Beispiel #1
0
 static void Test(Graph document, Triple clause)
 {
     Console.WriteLine(clause.Display());
     foreach (var entry in document.Match(clause))
     {
         Console.WriteLine(entry);
     }
 }
Beispiel #2
0
 static Triple MakeClause(Triple queryTriple)
 {
     return new Triple
     {
         Subject = queryTriple.Subject is Variable ? null : queryTriple.Subject,
         Predicate = queryTriple.Predicate is Variable ? null : queryTriple.Predicate,
         Object = queryTriple.Object is Variable ? null : queryTriple.Object
     };
 }
Beispiel #3
0
 static IDictionary<string, object> UpdateBinding(Triple queryTriple, Triple row, IDictionary<string, object> existingBinding)
 {
     var result = new Dictionary<string, object>(existingBinding);
     if (queryTriple.Subject is Variable)
     {
         var variableName = ((Variable)queryTriple.Subject).Value;
         var newValue = row.Subject;
         if (result.ContainsKey(variableName))
         {
             if (!result[variableName].Equals(newValue))
             {
                 return null;
             }
         }
         else
         {
             result[variableName] = newValue;
         }
     }
     if (queryTriple.Predicate is Variable)
     {
         var variableName = ((Variable)queryTriple.Predicate).Value;
         var newValue = row.Predicate;
         if (result.ContainsKey(variableName))
         {
             if (!result[variableName].Equals(newValue))
             {
                 return null;
             }
         }
         else
         {
             result[variableName] = newValue;
         }
     }
     if (queryTriple.Object is Variable)
     {
         var variableName = ((Variable)queryTriple.Object).Value;
         var newValue = row.Object;
         if (result.ContainsKey(variableName))
         {
             if (!result[variableName].Equals(newValue))
             {
                 return null;
             }
         }
         else
         {
             result[variableName] = newValue;
         }
     }
     return result;
 }
Beispiel #4
0
 static IDictionary<string, object> MakeBinding(Triple queryTriple, Triple row, IDictionary<string, object> parameters)
 {
     var result = new Dictionary<string, object>(parameters ?? new Dictionary<string, object>());
     if (queryTriple.Subject is Variable)
     {
         result[((Variable)queryTriple.Subject).Value] = row.Subject;
     }
     if (queryTriple.Predicate is Variable)
     {
         result[((Variable)queryTriple.Predicate).Value] = row.Predicate;
     }
     if (queryTriple.Object is Variable)
     {
         result[((Variable)queryTriple.Object).Value] = row.Object;
     }
     return result;
 }
Beispiel #5
0
 static Triple()
 {
     Empty = new Triple();
 }