public ResourceFactoryResponder()
 {
     itsUriRefResponse       = new UriRefStub();
     itsBlankNodeResponse    = new BlankNodeStub();
     itsTypedLiteralResponse = new TypedLiteralStub();
     itsPlainLiteralResponse = new PlainLiteralStub();
 }
Exemplo n.º 2
0
 public void writeCallsWriterWritePlainLiteralWithCorrectArgumentsWithLanguage() {
   RdfWriterStore writer = new RdfWriterStore();
   PlainLiteral instance = new PlainLiteral("whizz", "gr");
   
   instance.Write(writer);
   
   Assert.IsTrue( writer.WasWritePlainLiteralCalledWith("whizz", "gr") );
 }
Exemplo n.º 3
0
 public void matchesCallsMatchesPlainLiteralWithLanguageOnSpecifier() {
   ResourceSpecifierStore specifier = new ResourceSpecifierStore();
   PlainLiteral instance = new PlainLiteral("whizz", "de");
   
   instance.Matches( specifier );
   
   Assert.IsTrue( specifier.WasMatchesPlainLiteralCalledWith("whizz", "de") );
 }
Exemplo n.º 4
0
 public void matchesReturnsResponseFromMatchesPlainLiterallWithLanguageCall() {
   ResourceSpecifierResponder specifierTrue = new ResourceSpecifierResponder(true);
   ResourceSpecifierResponder specifierFalse = new ResourceSpecifierResponder(false);
   PlainLiteral instance = new PlainLiteral("whizz", "de");
   
   Assert.IsTrue( instance.Matches( specifierTrue ));
   Assert.IsFalse( instance.Matches( specifierFalse ));
 }
Exemplo n.º 5
0
        private void EnsureLanguageExistsInDb(PlainLiteral node)
        {
            int          hash = node.GetLanguage().GetHashCode();
            MySqlCommand cmd  = new MySqlCommand("INSERT IGNORE INTO Languages (hash, value) VALUES (" +
                                                 hash + ", '" + node.GetLanguage() + "')", itsConn);

            cmd.ExecuteNonQuery();
        }
Exemplo n.º 6
0
 public void writeCallsWriterWritePlainLiteralOnceWithLanguage() {
   RdfWriterCounter writer = new RdfWriterCounter();
   PlainLiteral instance = new PlainLiteral("whizz", "en");
   
   instance.Write(writer);
   
   Assert.AreEqual( 1, writer.WritePlainLiteralLanguageCalled );
 }
Exemplo n.º 7
0
        public void EvaluateReturnsGraphMember()
        {
            PlainLiteral          member     = new PlainLiteral("scooby");
            GraphMemberExpression constraint = new GraphMemberExpression(member);

            Bindings bindings = new Bindings();

            Assert.AreEqual(member, constraint.Evaluate(bindings));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Generates the triples.
        /// </summary>
        /// <param name="outputGraph">The Rdf graph.</param>
        private void GenerateTriples(Graph outputGraph)
        {
            //If e.subject is empty, then e.subject := bnodeid(identifier := generated-blank-node-id()).
            //The following can then be performed in any order:
            //    * If e.URI != rdf:Description then the following statement is added to the graph:
            //      e.subject.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> e.URI-string-value .
            //    * If there is an attribute a in propertyAttr with a.URI == rdf:type then u:=uri(identifier:=resolve(a.string-value)) and the following tiple is added to the graph:
            //      e.subject.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> u.string-value .
            //    * For each attribute a matching propertyAttr (and not rdf:type), the Unicode string a.string-value SHOULD be in Normal Form C[NFC], o := literal(literal-value := a.string-value, literal-language := e.language) and the following statement is added to the graph:
            //      e.subject.string-value a.URI-string-value o.string-value .

            Subject subject = GetSubject();

            if (subject != null)
            {
                innerElement.Subject = subject;
            }

            if (innerElement.Subject == null)
            {
                innerElement.Subject = new BlankNode();
            }

            if (innerElement.Uri != DescriptionUri)
            {
                AddTriple(outputGraph, innerElement.Subject, TypeUri, innerElement.Uri);
            }

            //propertyAttr = anyURI - ( coreSyntaxTerms | rdf:Description | rdf:li | oldTerms )
            IEnumerable <EventAttribute> propertyAttr =
                innerElement.Attributes.Where(tuple => tuple.Uri != DescriptionUri &&
                                              tuple.Uri != LiUri &&
                                              Production.CoreSyntaxTerms.Where(attr => attr == tuple.Uri).Count() == 0 &&
                                              Production.OldTerms.Where(attr => attr == tuple.Uri).Count() == 0);

            EventAttribute a = propertyAttr.
                               Where(tuple => tuple.Uri == TypeUri).FirstOrDefault();

            if (a != null)
            {
                RDFUriReference u = Production.Resolve(innerElement, a.StringValue);
                AddTriple(outputGraph, innerElement.Subject, TypeUri, u);
            }

            foreach (EventAttribute attr in
                     propertyAttr.Where(tuple => tuple.Uri != TypeUri))
            {
                PlainLiteral o = new PlainLiteral(attr.StringValue, innerElement.Language);
                AddTriple(outputGraph, innerElement.Subject, attr.Uri, o);
            }
        }
Exemplo n.º 9
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.º 11
0
 public void neverEqualsInstanceOfSameClassButDifferentLexicalValueAndNoLanguage() {
  PlainLiteral instance = new PlainLiteral("whizz");
  PlainLiteral other = new PlainLiteral("bang");
  
  Assert.IsFalse( instance.Equals(other) );
 }
Exemplo n.º 12
0
 public void alwaysEqualsSelf() {
  PlainLiteral instance = new PlainLiteral("whizz");
  
  Assert.IsTrue( instance.Equals(instance) );
 }
Exemplo n.º 13
0
 public void neverEqualsInstanceOfDifferentClass() {
  PlainLiteral instance = new PlainLiteral("whizz");
  Object obj = new Object();
  
  Assert.IsFalse( instance.Equals(obj) );
 }
Exemplo n.º 14
0
 public void neverEqualsNull() {
  PlainLiteral instance = new PlainLiteral("whizz");
  
  Assert.IsFalse( instance.Equals(null) );
 }
Exemplo n.º 15
0
 public void languageDefaultsToNull() {
   PlainLiteral node = new PlainLiteral("whizz");
   
   Assert.AreEqual(null, node.GetLanguage());
 }      
Exemplo n.º 16
0
 public void neverEqualsInstanceOfSameClassWithSameLexicalValueAndDifferentLanguage() {
  PlainLiteral instance = new PlainLiteral("whizz", "en");
  PlainLiteral other = new PlainLiteral("whizz", "fr");
  
  Assert.IsFalse( instance.Equals(other) );
 }
Exemplo n.º 17
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.º 18
0
        /// <summary>
        /// Creates a new PlainLiteral object that is a copy of the current instance.
        /// </summary>
        /// <returns>A new PlainLiteral object that is a copy of the current instance.</returns>
        public override object Clone()
        {
            PlainLiteral clonedLiteral = new PlainLiteral(this.LexicalForm, this.LanguageTag);

            return(clonedLiteral);
        }
Exemplo n.º 19
0
 public override Statement MakeStatement(UriRef subject, UriRef predicate, PlainLiteral value)
 {
     ++MakeStatementUUPCalled;
     return(new StatementStub());
 }
Exemplo n.º 20
0
 public override Statement MakeStatement(UriRef subject, UriRef predicate, PlainLiteral value)
 {
     itsMethodCalls.RecordMethodCall("MakeStatement", subject, predicate, value);
     return(new StatementStub());
 }
        /// <summary>
        /// Generates the triples.
        /// </summary>
        /// <param name="outputGraph">The Rdf graph.</param>
        private void GenerateTriples(Graph outputGraph)
        {
            //If there are no attributes or only the optional rdf:ID attribute i then
            //o := literal(literal-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 .
            EventAttribute i = innerElement.Attributes.
                               Where(tuple => tuple.Uri == IDUri).FirstOrDefault();

            if (innerElement.Attributes.Count() == 0 ||
                (innerElement.Attributes.Count() == 1 && i != null))
            {
                Subject         s = innerElement.Parent.Subject;
                RDFUriReference p = innerElement.Uri;
                Node            o = new PlainLiteral(string.Empty, innerElement.Language);

                AddTriple(outputGraph, s, p, o);

                //and then if i is given, the above statement is reified with
                //uri(identifier := resolve(e, concat("#", i.string-value)))
                //using the reification rules
                if (i != null)
                {
                    RDFUriReference elementUri = Production.Resolve(innerElement, ("#" + i.StringValue));
                    Production.Reify(s, p, o, elementUri, outputGraph);
                }
            }
            else
            {
                Subject r = GetSubject();

                //For all propertyAttr attributes a (in any order)
                //If a.URI == rdf:type then u:=uri(identifier:=resolve(a.string-value)) and the following triple is added to the graph:
                //r.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> u.string-value .
                //Otherwise Unicode string a.string-value SHOULD be in Normal Form C[NFC],
                //o := literal(literal-value := a.string-value, literal-language := e.language) and the following statement is added to the graph:
                //r.string-value a.URI-string-value o.string-value .

                //propertyAttr = anyURI - ( coreSyntaxTerms | rdf:Description | rdf:li | oldTerms )
                IEnumerable <EventAttribute> propertyAttr = innerElement.Attributes.
                                                            Where(tuple => tuple.Uri != DescriptionUri &&
                                                                  tuple.Uri != LiUri &&
                                                                  (Production.CoreSyntaxTerms.Where(attr => attr == tuple.Uri).Count() == 0) &&
                                                                  (Production.OldTerms.Where(attr => attr == tuple.Uri).Count() == 0));

                foreach (EventAttribute a in propertyAttr)
                {
                    if (a.Uri == TypeUri)
                    {
                        RDFUriReference u = Production.Resolve(innerElement, a.StringValue);
                        AddTriple(outputGraph, r, TypeUri, u);
                    }
                    //Attributes except rdf:resource and rdf:nodeID
                    else if (!(a.Uri == ResourceUri || a.Uri == NodeIDUri))
                    {
                        Node literal = new PlainLiteral(a.StringValue, innerElement.Language);
                        AddTriple(outputGraph, r, a.Uri, literal);
                    }
                }


                //Add the following statement to the graph:
                //e.parent.subject.string-value e.URI-string-value r.string-value .
                //and then if rdf:ID attribute i is given, the above statement is reified with uri(identifier := resolve(e, concat("#", i.string-value))) using the reification rules
                Subject         s = innerElement.Parent.Subject;
                RDFUriReference p = innerElement.Uri;
                Node            o = r;
                AddTriple(outputGraph, s, p, o);

                if (i != null)
                {
                    RDFUriReference elementUri = Production.Resolve(innerElement, ("#" + i.StringValue));
                    Production.Reify(s, p, o, elementUri, outputGraph);
                }
            }
        }
Exemplo n.º 22
0
 public void getHashCodeReturnsSameCodeForDifferentInstancesWithSameLexicalValuesAndSameLanguage() {
  PlainLiteral instance = new PlainLiteral("whizz", "en");
  PlainLiteral other = new PlainLiteral("whizz", "en");
  
  Assert.IsTrue( instance.GetHashCode() == other.GetHashCode() );
 }
Exemplo n.º 23
0
 public void getHashCodeReturnsDifferentCodeForDifferentInstancesWithSameLexicalValuesButDifferentLanguages() {
  PlainLiteral instance = new PlainLiteral("whizz", "en");
  PlainLiteral other = new PlainLiteral("whizz", "fr");
  
  Assert.IsFalse( instance.GetHashCode() == other.GetHashCode() );
 }
Exemplo n.º 24
0
 public void getHashCodeReturnsDifferentCodeForDifferentInstancesWithDifferentLexicalValues() {
  PlainLiteral instance = new PlainLiteral("whizz");
  PlainLiteral other = new PlainLiteral("bang");
  
  Assert.IsFalse( instance.GetHashCode() == other.GetHashCode() );
 }
Exemplo n.º 25
0
 public void alwaysEqualsInstanceOfSameClassWithSameLexicalValueAndNoLanguage() {
  PlainLiteral instance = new PlainLiteral("whizz");
  PlainLiteral other = new PlainLiteral("whizz");
  
  Assert.IsTrue( instance.Equals(other) );
 }
Exemplo n.º 26
0
 public override Statement MakeStatement(BlankNode subject, UriRef predicate, PlainLiteral value)
 {
     return(new StatementStub());
 }
Exemplo n.º 27
0
 public void labelIsLexicalValue() {
   PlainLiteral node = new PlainLiteral("whizz");
   
   Assert.AreEqual("whizz", node.GetLabel());
 }      
Exemplo n.º 28
0
 public void languageSpecifiedInConstructor() {
   PlainLiteral node = new PlainLiteral("whizz", "fr");
   
   Assert.AreEqual("fr", node.GetLanguage());
 }      
Exemplo n.º 29
0
 public bool WasMakeStatementCalledWith(UriRef subject, UriRef predicate, PlainLiteral value)
 {
     return(itsMethodCalls.WasMethodCalledWith("MakeStatement", subject, predicate, value));
 }