コード例 #1
0
        public void GetStatementEnumerator()
        {
            Node theSubject      = new NodeStub("http://example.com/subj");
            Arc  thePredicate    = new UriRef("http://example.com/pred");
            Node theFirstObject  = new UriRef("http://example.com/obj1");
            Node theSecondObject = new UriRef("http://example.com/obj2");

            Statement   statement1 = new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj1"));
            Statement   statement2 = new Statement(new BlankNode(), new UriRef("http://example.com/pred"), new UriRef("http://example.com/obj2"));
            TripleStore store      = MakeNewTripleStore();

            store.Add(statement1);
            store.Add(statement2);

            ResourceStatement resStatement1 = new ResourceStatement(store.GetResourceDenotedBy(statement1.GetSubject()), store.GetResourceDenotedBy(statement1.GetPredicate()), store.GetResourceDenotedBy(statement1.GetObject()));
            ResourceStatement resStatement2 = new ResourceStatement(store.GetResourceDenotedBy(statement2.GetSubject()), store.GetResourceDenotedBy(statement2.GetPredicate()), store.GetResourceDenotedBy(statement2.GetObject()));
            IEnumerator       statementEnum = store.GetStatementEnumerator();

            Assert.IsTrue(statementEnum.MoveNext(), "Enumerator has first statement");

            ResourceStatement firstStatement = (ResourceStatement)statementEnum.Current;

            Assert.IsTrue(statementEnum.MoveNext(), "Enumerator has second statement");

            ResourceStatement secondStatement = (ResourceStatement)statementEnum.Current;

            Assert.IsFalse(statementEnum.MoveNext());
            Assert.IsTrue((firstStatement.Equals(resStatement1) && secondStatement.Equals(resStatement2)) || (firstStatement.Equals(resStatement2) && secondStatement.Equals(resStatement1)), "Statements have correct components");
            store.Clear();
        }
コード例 #2
0
        public bool Contains(Statement statement)
        {
            if (!HasResourceDenotedBy(statement.GetSubject()))
            {
                return(false);
            }

            if (!HasResourceDenotedBy(statement.GetPredicate()))
            {
                return(false);
            }

            if (!HasResourceDenotedBy(statement.GetObject()))
            {
                return(false);
            }

            Resource theSubject   = GetResourceDenotedBy(statement.GetSubject());
            Resource thePredicate = GetResourceDenotedBy(statement.GetPredicate());
            Resource theObject    = GetResourceDenotedBy(statement.GetObject());

            ResourceStatement testStatement = new ResourceStatement(theSubject, thePredicate, theObject);

            return(Contains(testStatement));
        }
コード例 #3
0
        public bool Contains(ResourceStatement statement)
        {
            MySqlCommand cmd = new MySqlCommand("SELECT EXISTS (SELECT * FROM Statements s " +
                                                "WHERE s.graphId = " + itsHashCode + " AND s.subjectHash = " + statement.GetSubject().GetHashCode() +
                                                " AND s.predicateHash = " + statement.GetPredicate().GetHashCode() + " AND s.objectHash = " + statement.GetObject().GetHashCode() + ")", itsConn);

            return(Convert.ToInt32(cmd.ExecuteScalar()) > 0);
        }
コード例 #4
0
        public void Remove(ResourceStatement resourceStatement)
        {
            MySqlCommand cmd = new MySqlCommand("DELETE FROM Statements WHERE " +
                                                "subjectHash =  " + resourceStatement.GetSubject().GetHashCode() + " AND " +
                                                "predicateHash =  " + resourceStatement.GetPredicate().GetHashCode() + " AND " +
                                                "objectHash =  " + resourceStatement.GetObject().GetHashCode() + " AND " +
                                                "graphId =  " + itsHashCode, itsConn);

            cmd.ExecuteNonQuery();
        }
コード例 #5
0
        public bool Contains(GraphMember thePredicate, Resource theObjectResource)
        {
            if (!itsStore.HasResourceDenotedBy(thePredicate))
            {
                return(false);
            }

            Resource thePredicateResource = itsStore.GetResourceDenotedBy(thePredicate);

            ResourceStatement testStatement = new ResourceStatement(itsResource, thePredicateResource, theObjectResource);

            return(itsStore.Contains(testStatement));
        }
コード例 #6
0
        public void Merge(ResourceStatementCollection statements, ResourceMap map)
        {
            IEnumerator statementEnumerator = statements.GetStatementEnumerator();

            while (statementEnumerator.MoveNext())
            {
                ResourceStatement resStatement = (ResourceStatement)statementEnumerator.Current;
                Node      theSubject           = (Node)map.GetBestDenotingNode(resStatement.GetSubject());
                Arc       thePredicate         = (Arc)map.GetBestDenotingNode(resStatement.GetPredicate());
                Node      theObject            = (Node)map.GetBestDenotingNode(resStatement.GetObject());
                Statement statement            = new Statement(theSubject, thePredicate, theObject);
                Add(statement);
            }
        }
コード例 #7
0
        public void Merge(ResourceStatementCollection statements, ResourceMap map)
        {
            if (this == statements)
            {
                return;
            }

            Hashtable equivalentResources = new Hashtable();

            foreach (Resource resource in statements.ReferencedResources)
            {
                Resource internalResource = resource;

                foreach (GraphMember member in map.GetNodesDenoting(resource))
                {
                    if (HasResourceDenotedBy(member))
                    {
                        internalResource = GetResourceDenotedBy(member);
                        equivalentResources[resource] = internalResource;
                        break;
                    }

                    // Must be a new resource
                    // Remember this for when we're Adding statements
                    // TODO: move this outside the loop
                    equivalentResources[resource] = resource;
                }

                foreach (GraphMember member in map.GetNodesDenoting(resource))
                {
                    AddDenotation(member, internalResource);
                }
            }

            IEnumerator statementEnumerator = statements.GetStatementEnumerator();

            while (statementEnumerator.MoveNext())
            {
                ResourceStatement statement         = (ResourceStatement)statementEnumerator.Current;
                ResourceStatement internalStatement = new ResourceStatement((Resource)equivalentResources[statement.GetSubject()],
                                                                            (Resource)equivalentResources[statement.GetPredicate()],
                                                                            (Resource)equivalentResources[statement.GetObject()]);
                Add(internalStatement);
            }
        }
コード例 #8
0
        public void Add(GraphMember thePredicate, Resource theObjectResource)
        {
            Resource thePredicateResource;

            if (itsStore.HasResourceDenotedBy(thePredicate))
            {
                thePredicateResource = itsStore.GetResourceDenotedBy(thePredicate);
            }
            else
            {
                thePredicateResource = itsStore.MakeNewResourceForNode(thePredicate);
                itsStore.AddDenotation(thePredicate, thePredicateResource);
            }

            ResourceStatement resourceStatement = new ResourceStatement(itsResource, thePredicateResource, theObjectResource);

            itsStore.Add(resourceStatement);
        }
コード例 #9
0
        public void Add(Statement statement)
        {
            Resource theSubject;

            if (HasResourceDenotedBy(statement.GetSubject()))
            {
                theSubject = GetResourceDenotedBy(statement.GetSubject());
            }
            else
            {
                theSubject = MakeNewResourceForNode(statement.GetSubject());
                AddDenotation(statement.GetSubject(), theSubject);
            }

            Resource thePredicate;

            if (HasResourceDenotedBy(statement.GetPredicate()))
            {
                thePredicate = GetResourceDenotedBy(statement.GetPredicate());
            }
            else
            {
                thePredicate = MakeNewResourceForNode(statement.GetPredicate());
                AddDenotation(statement.GetPredicate(), thePredicate);
            }

            Resource theObject;

            if (HasResourceDenotedBy(statement.GetObject()))
            {
                theObject = GetResourceDenotedBy(statement.GetObject());
            }
            else
            {
                theObject = MakeNewResourceForNode(statement.GetObject());
                AddDenotation(statement.GetObject(), theObject);
            }

            ResourceStatement resourceStatement = new ResourceStatement(theSubject, thePredicate, theObject);

            Add(resourceStatement);
        }
コード例 #10
0
        public void Add(ResourceStatement resourceStatement)
        {
            if (!itsResourceStatements.ContainsKey(resourceStatement))
            {
                if (!HasNodeDenoting(resourceStatement.GetSubject()))
                {
                    AddDenotation(MakeNameForResource(resourceStatement.GetSubject()), resourceStatement.GetSubject());
                }
                if (!HasNodeDenoting(resourceStatement.GetPredicate()))
                {
                    AddDenotation(MakeNameForResource(resourceStatement.GetPredicate()), resourceStatement.GetPredicate());
                }
                if (!HasNodeDenoting(resourceStatement.GetObject()))
                {
                    AddDenotation(MakeNameForResource(resourceStatement.GetObject()), resourceStatement.GetObject());
                }

                itsResourceStatements[resourceStatement] = resourceStatement;
            }
        }
コード例 #11
0
        public void Write(RdfWriter writer)
        {
            writer.StartOutput();
            IEnumerator statementEnum = GetStatementEnumerator();

            while (statementEnum.MoveNext())
            {
                ResourceStatement statement = (ResourceStatement)statementEnum.Current;
                writer.StartSubject();
                GetBestDenotingNode(statement.GetSubject()).Write(writer);
                writer.StartPredicate();
                GetBestDenotingNode(statement.GetPredicate()).Write(writer);
                writer.StartObject();
                GetBestDenotingNode(statement.GetObject()).Write(writer);
                writer.EndObject();
                writer.EndPredicate();
                writer.EndSubject();
            }
            writer.EndOutput();
        }
コード例 #12
0
ファイル: KnowledgeBase.cs プロジェクト: Titan512/spiralrdf
        public virtual void Replace(ConciseBoundedDescription description)
        {
            Resource  internalSubjectResource = GetResourceDescribedBy(description);
            ArrayList statementsToRemove      = new ArrayList();

            IEnumerator statementEnumerator = itsAssertions.GetStatementEnumerator();

            while (statementEnumerator.MoveNext())
            {
                ResourceStatement statement = (ResourceStatement)statementEnumerator.Current;
                if (statement.GetSubject().Equals(internalSubjectResource))
                {
                    statementsToRemove.Add(statement);
                }
            }

            foreach (ResourceStatement statement in statementsToRemove)
            {
                itsAssertions.Remove(statement);
            }

            Add(description);
        }
コード例 #13
0
 public void Add(ResourceStatement statement)
 {
     AddStatement(statement.GetSubject().GetHashCode(), statement.GetPredicate().GetHashCode(), statement.GetObject().GetHashCode());
 }
コード例 #14
0
 public bool Contains(ResourceStatement resourceStatement)
 {
     return(itsResourceStatements.ContainsKey(resourceStatement));
 }
コード例 #15
0
 public bool Contains(ResourceStatement statement)
 {
     return(itsStore.Contains(statement));
 }
コード例 #16
0
 public void Remove(ResourceStatement resourceStatement)
 {
     itsResourceStatements.Remove(resourceStatement);
 }
コード例 #17
0
 public void Remove(ResourceStatement resourceStatement)
 {
     itsStore.Remove(resourceStatement);
 }
コード例 #18
0
 public void Add(ResourceStatement statement)
 {
     //NOOP
 }
コード例 #19
0
 public bool Contains(ResourceStatement resourceStatement)
 {
     return(false);
 }
コード例 #20
0
 public void Add(ResourceStatement statement)
 {
     itsStore.Add(statement);
 }
コード例 #21
0
        public ArrayList GetSolutions(TripleStore store, QueryGroup group, Bindings bindings)
        {
            if (Explain)
            {
                Console.WriteLine("Solving " + group.GetType());
            }

            if (group is QueryGroupOr)
            {
                if (Explain)
                {
                    Console.WriteLine("Solving QueryGroupOr");
                }
                ArrayList solutions = new ArrayList();
                foreach (QueryGroup subgroup in ((QueryGroupOr)group).Groups)
                {
                    solutions.AddRange(GetSolutions(store, subgroup, bindings));
                }
                if (Explain)
                {
                    Console.WriteLine("Have " + solutions.Count + " candidate solutions after or");
                }

                return(solutions);
            }
            else if (group is QueryGroupAnd)
            {
                ArrayList solutions = new ArrayList();
                solutions.Add(bindings);

                foreach (QueryGroup subgroup in ((QueryGroupAnd)group).Groups)
                {
                    ArrayList filteredSolutions = new ArrayList();
                    foreach (Bindings tempBindings in solutions)
                    {
                        filteredSolutions.AddRange(GetSolutions(store, subgroup, tempBindings));
                    }
                    solutions = filteredSolutions;
                    if (Explain)
                    {
                        Console.WriteLine("Have " + solutions.Count + " candidate solutions after " + subgroup.GetType());
                    }
                }
                return(solutions);
            }

            else if (group is QueryGroupOptional)
            {
                if (Explain)
                {
                    Console.WriteLine("Solving QueryGroupOptional");
                }
                ArrayList augmentedSolutions = GetSolutions(store, ((QueryGroupOptional)group).Group, bindings);

                if (augmentedSolutions.Count == 0)
                {
                    augmentedSolutions.Add(bindings);
                }

                return(augmentedSolutions);
            }
            else if (group is QueryGroupConstraints)
            {
                if (Explain)
                {
                    Console.WriteLine("Solving QueryGroupConstraints");
                }
                ArrayList solutions = new ArrayList();
                foreach (Constraint constraint in ((QueryGroupConstraints)group).Constraints)
                {
                    if (Explain)
                    {
                        Console.WriteLine("Testing solution against constraint {0}", constraint);
                    }
                    if (!constraint.SatisfiedBy(bindings))
                    {
                        if (Explain)
                        {
                            Console.WriteLine("Failed to satisfy constraint");
                        }
                        return(solutions);
                    }
                }

                solutions.Add(bindings);
                return(solutions);
            }
            else if (group is QueryGroupPatterns)
            {
                if (Explain)
                {
                    Console.WriteLine("Solving QueryGroupPatterns");
                }
                ArrayList solutions = new ArrayList();

                if (((QueryGroupPatterns)group).Patterns.Count == 0)
                {
                    return(solutions);
                }

                Bindings answers = new Bindings();

                Pattern firstGoal = ((QueryGroupPatterns)group).First();
                Pattern newGoal   = firstGoal.Substitute(bindings);

                IEnumerator statements = store.GetStatementEnumerator();
                while (statements.MoveNext())
                {
                    ResourceStatement statement = (ResourceStatement)statements.Current;

                    if (Explain)
                    {
                        Console.WriteLine("Trying for a binding for {0} with {1}", statement, newGoal);
                    }
                    answers = statement.Unify(newGoal, bindings, store);

                    if (answers != null)
                    {
                        if (Explain)
                        {
                            Console.WriteLine("Got a binding for {0} with {1}", statement, newGoal);
                        }
                        if (((QueryGroupPatterns)group).Patterns.Count == 1)
                        {
                            if (Explain)
                            {
                                Console.WriteLine("Got a candidate solution {0}", answers);
                            }
                            solutions.Add(answers);
                        }
                        else
                        {
                            solutions.AddRange(GetSolutions(store, ((QueryGroupPatterns)group).Rest(), answers));
                        }
                    }
                }

                return(solutions);
            }
            else
            {
                return(new ArrayList());
            }
        }
コード例 #22
0
 public void Remove(ResourceStatement resourceStatement)
 {
     //NOOP
 }