Exemplo n.º 1
0
        public void getHashCodeReturnsDifferentCodeForDifferentInstancesWithDifferentDataTypes()
        {
            TypedLiteral instance = new TypedLiteral("whizz", "http://example.com/datatype");
            TypedLiteral other    = new TypedLiteral("whizz", "http://example.com/other");

            Assert.IsFalse(instance.GetHashCode() == other.GetHashCode());
        }
Exemplo n.º 2
0
        public void neverEqualsInstanceOfSameClassWithDifferentLexicalValueAndSameDataType()
        {
            TypedLiteral instance = new TypedLiteral("whizz", "http://example.com/datatype");
            TypedLiteral other    = new TypedLiteral("bang", "http://example.com/datatype");

            Assert.IsFalse(instance.Equals(other));
        }
Exemplo n.º 3
0
        public void alwaysEqualsInstanceOfSameClassWithSameLexicalValueAndSameDataType()
        {
            TypedLiteral instance = new TypedLiteral("whizz", "http://example.com/datatype");
            TypedLiteral other    = new TypedLiteral("whizz", "http://example.com/datatype");

            Assert.IsTrue(instance.Equals(other));
        }
 public ResourceFactoryResponder()
 {
     itsUriRefResponse       = new UriRefStub();
     itsBlankNodeResponse    = new BlankNodeStub();
     itsTypedLiteralResponse = new TypedLiteralStub();
     itsPlainLiteralResponse = new PlainLiteralStub();
 }
Exemplo n.º 5
0
        public void neverEqualsInstanceOfDifferentClass()
        {
            TypedLiteral instance = new TypedLiteral("whizz", "http://example.com/datatype");
            Object       obj      = new Object();

            Assert.IsFalse(instance.Equals(obj));
        }
        /// <summary>
        /// Generates the triples.
        /// </summary>
        /// <param name="outputGraph">The Rdf graph.</param>
        private void GenerateTriples(Graph outputGraph)
        {
            //For element e and the literal l that is the rdf:parseType="Literal" content. l is not transformed by the syntax data model mapping into events (as noted in 6 Syntax Data Model) but remains an XML Infoset of XML Information items.
            //l is transformed into the lexical form of an XML literal in the RDF graph x (a Unicode string) by the following algorithm. This does not mandate any implementation method — any other method that gives the same result may be used.
            //Use l to construct an XPath[XPATH] node-set (a document subset)
            //Apply Exclusive XML Canonicalization [XML-XC14N]) with comments and with empty InclusiveNamespaces PrefixList to this node-set to give a sequence of octets s
            //This sequence of octets s can be considered to be a UTF-8 encoding of some Unicode string x (sequence of Unicode characters)
            //The Unicode string x is used as the lexical form of l
            //This Unicode string x SHOULD be in NFC Normal Form C[NFC]
            //Then o := typed-literal(literal-value := x, literal-datatype := http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral ) and the following statement is added to the graph:
            //e.parent.subject.string-value e.URI-string-value o.string-value .

            //TODO: Check for XML Encoding/Decoding.
            string x = innerElement.StringValue;

            Subject         s = innerElement.Parent.Subject;
            RDFUriReference p = innerElement.Uri;
            Node            o = new TypedLiteral(x, TypedLiteral.XmlLiteralDataTypeUri);

            AddTriple(outputGraph, s, p, o);

            //If the rdf:ID attribute a is given, the above statement is reified with
            //i := uri(identifier := resolve(e, concat("#", a.string-value)))
            //using the reification rules and e.subject := i.
            EventAttribute a = innerElement.Attributes.
                               Where(tuple => tuple.Uri == IDUri).FirstOrDefault();

            if (a != null)
            {
                RDFUriReference i = Production.Resolve(innerElement, ("#" + a.StringValue));

                Production.Reify(s, p, o, i, outputGraph);
            }
        }
Exemplo n.º 7
0
        public void getHashCodeReturnsSameCodeForDifferentInstancesWithSameLexicalValuesAndDataTypes()
        {
            TypedLiteral instance = new TypedLiteral("whizz", "http://example.com/datatype");
            TypedLiteral other    = new TypedLiteral("whizz", "http://example.com/datatype");

            Assert.IsTrue(instance.GetHashCode() == other.GetHashCode());
        }
Exemplo n.º 8
0
        private void EnsureDatatypeExistsInDb(TypedLiteral node)
        {
            int          hash = node.GetDataType().GetHashCode();
            MySqlCommand cmd  = new MySqlCommand("INSERT IGNORE INTO Datatypes (hash, value) VALUES (" +
                                                 hash + ", '" + node.GetDataType() + "')", itsConn);

            cmd.ExecuteNonQuery();
        }
Exemplo n.º 9
0
        public void writeCallsWriterWritePlainLiteralWithCorrectArgumentsWithLanguage()
        {
            RdfWriterStore writer   = new RdfWriterStore();
            TypedLiteral   instance = new TypedLiteral("whizz", "http://example.com/datatype");

            instance.Write(writer);

            Assert.IsTrue(writer.WasWriteTypedLiteralCalledWith("whizz", "http://example.com/datatype"));
        }
Exemplo n.º 10
0
        public void matchesCallsMatchesTypedLiteralWithoutLanguageOnSpecifier()
        {
            ResourceSpecifierStore specifier = new ResourceSpecifierStore();
            TypedLiteral           instance  = new TypedLiteral("whizz", "http://example.com/type");

            instance.Matches(specifier);

            Assert.IsTrue(specifier.WasMatchesTypedLiteralCalledWith("whizz", "http://example.com/type"));
        }
Exemplo n.º 11
0
        public void matchesReturnsResponseFromMatchesTypedLiterallWithoutLanguageCall()
        {
            ResourceSpecifierResponder specifierTrue  = new ResourceSpecifierResponder(true);
            ResourceSpecifierResponder specifierFalse = new ResourceSpecifierResponder(false);
            TypedLiteral instance = new TypedLiteral("whizz", "http://example.com/type");

            Assert.IsTrue(instance.Matches(specifierTrue));
            Assert.IsFalse(instance.Matches(specifierFalse));
        }
Exemplo n.º 12
0
        public void writeCallsWriterWriteTypedLiteralOnce()
        {
            RdfWriterCounter writer   = new RdfWriterCounter();
            TypedLiteral     instance = new TypedLiteral("whizz", "http://example.com/datatype");

            instance.Write(writer);

            Assert.AreEqual(1, writer.WriteTypedLiteralCalled);
        }
Exemplo n.º 13
0
        private IList GetNodesDenoting(Resource theResource, bool onlyTheBest)
        {
            ArrayList    theNodes = new ArrayList();
            MySqlCommand cmd      = new MySqlCommand(
                "SELECT rn.nodeHash, rn.nodeType, u.uri, pl.value, l.value, tl.value, t.value " +
                "FROM resourcenodes rn " +
                "LEFT OUTER JOIN UriRefs u ON rn.nodeHash=u.hash AND rn.nodeType='u' " +
                "LEFT OUTER JOIN Plainliterals pl ON rn.nodeHash = pl.hash AND rn.nodeType='p' " +
                "LEFT OUTER JOIN Languages l ON pl.languageHash = l.hash " +
                "LEFT OUTER JOIN TypedLiterals tl ON rn.nodehash = tl.hash AND rn.nodeType = 't' " +
                "LEFT OUTER JOIN DataTypes t ON tl.datatypeHash = t.hash " +
                "WHERE rn.graphId = " + itsHashCode + " AND rn.resourceHash = " + theResource.GetHashCode() + (onlyTheBest == true ? " LIMIT 1" : ""), itsConn);
            MySqlDataReader dataReader = cmd.ExecuteReader();
            int             nodeHash;
            char            nodeType;

            while (dataReader.Read())
            {
                nodeHash = dataReader.GetInt32(0);
                nodeType = dataReader.GetChar(1);
                GraphMember node = null;
                switch (nodeType)
                {
                case 'u':
                    node = new UriRef(dataReader.GetString(2));
                    break;

                case 'b':
                    node = new BlankNode(nodeHash);
                    break;

                case 'p':
                    node = new PlainLiteral(dataReader.GetString(3), dataReader.GetString(4));
                    break;

                case 't':
                    node = new TypedLiteral(dataReader.GetString(5), dataReader.GetString(6));
                    break;
                }
                theNodes.Add(node);
            }
            dataReader.Close();
            return(theNodes);
        }
        /// <summary>
        /// Generates the triples.
        /// </summary>
        /// <param name="outputGraph">The Rdf graph.</param>
        private void GenerateTriples(Graph outputGraph)
        {
            //For element e, and the text event t. The Unicode string t.string-value SHOULD
            //be in Normal Form C[NFC].
            //If the rdf:datatype attribute d is given then o :=
            //typed-literal(literal-value := t.string-value, literal-datatype := d.string-value)
            //otherwise o := literal(literal-value := t.string-value, literal-language := e.language)
            //and the following statement is added to the graph:
            //e.parent.subject.string-value e.URI-string-value o.string-value .
            //  If the rdf:ID attribute a is given, the above statement is reified
            //with i := uri(identifier := resolve(e, concat("#", a.string-value)))
            //using the reification rules in section 7.3 and e.subject := i.
            Subject         s = innerElement.Parent.Subject;
            RDFUriReference p = innerElement.Uri;
            Node            o = null;

            EventAttribute d = innerElement.Attributes.
                               Where(tuple => tuple.Uri == DatatypeUri).FirstOrDefault();

            if (d != null)
            {
                o = new TypedLiteral(innerElement.StringValue,
                                     Production.Resolve(innerElement, d.StringValue));
            }
            else
            {
                o = new PlainLiteral(innerElement.StringValue, innerElement.Language);
            }

            AddTriple(outputGraph, s, p, o);

            EventAttribute a = innerElement.Attributes.
                               Where(tuple => tuple.Uri == IDUri).FirstOrDefault();

            if (a != null)
            {
                RDFUriReference i = Production.Resolve(innerElement, ("#" + a.StringValue));

                Production.Reify(s, p, o, i, outputGraph);
            }
        }
Exemplo n.º 15
0
        public void ExecuteQuery()
        {
            ArrayList solutions = new ArrayList();

            if (SolutionIsPossible)
            {
                MySqlDataReader dataReader = null;
                try {
                    dataReader = itsTriples.ExecuteSqlQuery(itsQuerySql);
                    while (dataReader.Read())
                    {
                        QuerySolution solution = new QuerySolution();
                        int           col      = 0;
                        foreach (Variable var in itsSelectedVariables)
                        {
                            object resourceHash = dataReader.GetValue(col);
                            if (!resourceHash.Equals(DBNull.Value))
                            {
                                Resource resource = new Resource(Convert.ToInt32(resourceHash));
                                solution[var.Name] = resource;

                                int    nodeHash     = dataReader.GetInt32(col + 1);
                                char   nodeType     = dataReader.GetChar(col + 2);
                                string lexicalValue = dataReader.GetString(col + 3);
                                object rawSubValue  = dataReader.GetValue(col + 4);
                                string subValue     = null;
                                if (!rawSubValue.Equals(DBNull.Value))
                                {
                                    subValue = (string)rawSubValue;
                                }

                                GraphMember node = null;
                                switch (nodeType)
                                {
                                case 'u':
                                    node = new UriRef(lexicalValue);
                                    break;

                                case 'b':
                                    node = new BlankNode(nodeHash);
                                    break;

                                case 'p':
                                    node = new PlainLiteral(lexicalValue, subValue);
                                    break;

                                case 't':
                                    node = new TypedLiteral(lexicalValue, subValue);
                                    break;
                                }

                                solution.SetNode(var.Name, node);
                            }
                            col += 5;
                        }
                        solutions.Add(solution);
                    }
                }
                catch (MySqlException e) {
                    throw new ApplicationException("Error executing '" + itsQuerySql + "' for query " + itsQuery, e);
                }
                finally {
                    if (null != dataReader)
                    {
                        dataReader.Close();
                    }
                }
            }

            itsSolutions = solutions.GetEnumerator();
        }
Exemplo n.º 16
0
 public override Statement MakeStatement(UriRef subject, UriRef predicate, TypedLiteral value)
 {
     ++MakeStatementUUTCalled;
     return(new StatementStub());
 }
Exemplo n.º 17
0
        public void alwaysEqualsSelf()
        {
            TypedLiteral instance = new TypedLiteral("whizz", "http://example.com/datatype");

            Assert.IsTrue(instance.Equals(instance));
        }
Exemplo n.º 18
0
        public void dataTypeIsStored()
        {
            TypedLiteral node = new TypedLiteral("whizz", "http://example.com/datatype");

            Assert.AreEqual("http://example.com/datatype", node.GetDataType());
        }
Exemplo n.º 19
0
        public void neverEqualsNull()
        {
            TypedLiteral instance = new TypedLiteral("whizz", "http://example.com/datatype");

            Assert.IsFalse(instance.Equals(null));
        }
Exemplo n.º 20
0
        public void labelIsLexicalValue()
        {
            TypedLiteral node = new TypedLiteral("whizz", "http://example.com/datatype");

            Assert.AreEqual("whizz", node.GetLabel());
        }
Exemplo n.º 21
0
 public override Statement MakeStatement(BlankNode subject, UriRef predicate, TypedLiteral value)
 {
     itsMethodCalls.RecordMethodCall("MakeStatement", subject, predicate, value);
     return(new StatementStub());
 }
Exemplo n.º 22
0
 public bool WasMakeStatementCalledWith(BlankNode subject, UriRef predicate, TypedLiteral value)
 {
     return(itsMethodCalls.WasMethodCalledWith("MakeStatement", subject, predicate, value));
 }
Exemplo n.º 23
0
 public override Statement MakeStatement(BlankNode subject, UriRef predicate, TypedLiteral value)
 {
     return(new StatementStub());
 }
Exemplo n.º 24
0
        public Statement ParseEdge(IRdfEdge edge)
        {
            // Nasty hack follows
            UriRef thePredicate = itsResourceFactory.MakeUriRef(edge.ID);

            NodeType subjectNodeType;
            NodeType objectNodeType;

            if (edge.ParentNode.ID.StartsWith("blankID:"))
            {
                subjectNodeType = NodeType.BLANK_NODE;
            }
            else
            {
                subjectNodeType = NodeType.URIREF;
            }

            if (edge.ChildNode is IRdfLiteral)
            {
                if (((IRdfLiteral)edge.ChildNode).Datatype == "")
                {
                    objectNodeType = NodeType.PLAIN_LITERAL;
                }
                else
                {
                    objectNodeType = NodeType.TYPED_LITERAL;
                }
            }
            else if (edge.ChildNode.ID.StartsWith("blankID:"))
            {
                objectNodeType = NodeType.BLANK_NODE;
            }
            else
            {
                objectNodeType = NodeType.URIREF;
            }


            if (subjectNodeType == NodeType.BLANK_NODE)
            {
                BlankNode theSubject = itsResourceFactory.MakeBlankNode("drive" + edge.ParentNode.ID.Substring(8));

                if (objectNodeType == NodeType.BLANK_NODE)
                {
                    BlankNode theObject = itsResourceFactory.MakeBlankNode("drive" + edge.ChildNode.ID.Substring(8));
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.URIREF)
                {
                    UriRef theObject = itsResourceFactory.MakeUriRef(edge.ChildNode.ID);
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.PLAIN_LITERAL)
                {
                    PlainLiteral theObject;
                    if (((IRdfLiteral)edge.ChildNode).LangID == null)
                    {
                        theObject = itsResourceFactory.MakePlainLiteral(((IRdfLiteral)edge.ChildNode).Value);
                    }
                    else
                    {
                        theObject = itsResourceFactory.MakePlainLiteral(((IRdfLiteral)edge.ChildNode).Value, ((IRdfLiteral)edge.ChildNode).LangID);
                    }
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.TYPED_LITERAL)
                {
                    TypedLiteral theObject = itsResourceFactory.MakeTypedLiteral(((IRdfLiteral)edge.ChildNode).Value, ((IRdfLiteral)edge.ChildNode).Datatype);
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
            }
            else
            {
                UriRef theSubject = itsResourceFactory.MakeUriRef(edge.ParentNode.ID);

                if (objectNodeType == NodeType.BLANK_NODE)
                {
                    BlankNode theObject = itsResourceFactory.MakeBlankNode("drive" + edge.ChildNode.ID.Substring(8));
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.URIREF)
                {
                    UriRef theObject = itsResourceFactory.MakeUriRef(edge.ChildNode.ID);
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.PLAIN_LITERAL)
                {
                    PlainLiteral theObject;
                    if (((IRdfLiteral)edge.ChildNode).LangID == null)
                    {
                        theObject = itsResourceFactory.MakePlainLiteral(((IRdfLiteral)edge.ChildNode).Value);
                    }
                    else
                    {
                        theObject = itsResourceFactory.MakePlainLiteral(((IRdfLiteral)edge.ChildNode).Value, ((IRdfLiteral)edge.ChildNode).LangID);
                    }
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.TYPED_LITERAL)
                {
                    TypedLiteral theObject = itsResourceFactory.MakeTypedLiteral(((IRdfLiteral)edge.ChildNode).Value, ((IRdfLiteral)edge.ChildNode).Datatype);
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
            }

            return(null);
        }