/// <summary>
        /// Generates the triples.
        /// </summary>
        /// <param name="outputGraph">The output graph.</param>
        /// <param name="idAttributeCount">The attribute count.</param>
        private void GenerateTriples(Graph outputGraph, int idAttributeCount)
        {
            //For element e, and the single contained nodeElement n, first n
            //must be processed using production nodeElement. Then the following
            //statement is added to the graph:
            //e.parent.subject.string-value e.URI-string-value n.subject.string-value .
            EventElement          n           = innerElement.Children.First();
            ProductionNodeElement nodeElement =
                new ProductionNodeElement(n);

            nodeElement.Match(outputGraph);

            Subject         subjectUri   = innerElement.Parent.Subject;
            RDFUriReference predicateUri = innerElement.Uri;
            Node            objectUri    = n.Subject;

            AddTriple(outputGraph, subjectUri, predicateUri, objectUri);

            //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
            if (idAttributeCount == 1)
            {
                EventAttribute  idAttr     = innerElement.Attributes.First();
                RDFUriReference elementUri = Production.Resolve(innerElement, ("#" + idAttr.StringValue));
                Production.Reify(subjectUri, predicateUri, objectUri, elementUri, outputGraph);
            }
        }
        /// <summary>
        /// Generates the triples.
        /// </summary>
        /// <param name="outputGraph">The Rdf graph.</param>
        /// <returns>REturns a Blank Node.</returns>
        private BlankNode GenerateTriples(Graph outputGraph)
        {
            //For element e with possibly empty element content c.
            //n := bnodeid(identifier := generated-blank-node-id()).
            //Add the following statement to the graph:
            //e.parent.subject.string-value  e.URI-string-value   n.string-value .
            BlankNode       n = new BlankNode();
            Subject         s = innerElement.Parent.Subject;
            RDFUriReference p = innerElement.Uri;

            AddTriple(outputGraph, s, p, n);

            //If the rdf:ID attribute a is given, the statement above 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, n, i, outputGraph);
            }

            return(n);
        }
        /// <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);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the subject.
        /// </summary>
        /// <returns>Returns a subject object.</returns>
        private Subject GetSubject()
        {
            //For node element e, the processing of some of the attributes has to be done before other work such as dealing with children events or other attributes. These can be processed in any order:
            //    * If there is an attribute a with a.URI == rdf:ID, then e.subject := uri(identifier := resolve(e, concat("#", a.string-value))).
            //    * If there is an attribute a with a.URI == rdf:nodeID, then e.subject := bnodeid(identifier:=a.string-value).
            //    * If there is an attribute a with a.URI == rdf:about then e.subject := uri(identifier := resolve(e, a.string-value)).

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

            if (idAttribute != null)
            {
                return(Production.Resolve(innerElement, "#" + idAttribute.StringValue));
            }

            EventAttribute nodeIdAttribute = innerElement.Attributes.
                                             Where(tuple => tuple.Uri == NodeIDUri).FirstOrDefault();

            if (nodeIdAttribute != null)
            {
                return(new BlankNode(nodeIdAttribute.StringValue));
            }

            EventAttribute aboutAttribute = innerElement.Attributes.
                                            Where(tuple => tuple.Uri == AboutUri).FirstOrDefault();

            if (aboutAttribute != null)
            {
                return(Production.Resolve(innerElement, aboutAttribute.StringValue));
            }

            return(null);
        }
        /// <summary>
        /// Gets the subject.
        /// </summary>
        /// <returns>Returns a node which is a subject of a triple.s</returns>
        private Subject GetSubject()
        {
            //If rdf:resource attribute i is present, then r := uri(identifier := resolve(e, i.string-value))
            //If rdf:nodeID attribute i is present, then r := bnodeid(identifier := i.string-value)
            //If neither, r := bnodeid(identifier := generated-blank-node-id())
            Subject        r            = null;
            EventAttribute resourceAttr = innerElement.Attributes.
                                          Where(tuple => tuple.Uri == ResourceUri).FirstOrDefault();

            if (resourceAttr != null)
            {
                r = Production.Resolve(innerElement, resourceAttr.StringValue);
            }

            if (r == null)
            {
                EventAttribute nodeIDAttr = innerElement.Attributes.
                                            Where(tuple => tuple.Uri == NodeIDUri).FirstOrDefault();
                if (nodeIDAttr != null)
                {
                    r = new BlankNode(nodeIDAttr.StringValue);
                }
            }

            if (r == null)
            {
                r = new BlankNode();
            }
            return(r);
        }
        /// <summary>
        /// Validates datatype attribute based on following syntax rules,
        /// <br/>
        /// attribute(URI == rdf:datatype, string-value == URI-reference)
        /// </summary>
        /// <param name="outputGraph">Graph to add the generated triples.</param>
        internal override void Match(Graph outputGraph)
        {
            if (innerAttribute.Uri != DatatypeUri)
            {
                throw new RdfXmlParserException(Constants.ErrorMessageIds.MsgDataTypeAttributeUriNotMatch, innerAttribute.LineInfo);
            }

            //This function call raises RdfXmlParserException if string value is
            //invalid Uri reference.
            Production.Resolve(innerAttribute.Parent, innerAttribute.StringValue);
        }
Esempio n. 7
0
        /// <summary>
        /// Generates the triples.
        /// </summary>
        /// <param name="outputGraph">The Rdf graph.</param>
        private void GenerateTriples(Graph outputGraph)
        {
            //For element event e with possibly empty nodeElementList l. Set s:=list().
            //For each element event f in l, n := bnodeid(identifier := generated-blank-node-id()) and append n to s to give a sequence of events.
            //If s is not empty, n is the first event identifier in s and the following statement is added to the graph:
            //e.parent.subject.string-value e.URI-string-value n.string-value .
            //otherwise the following statement is added to the graph:
            //e.parent.subject.string-value e.URI-string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
            List <Subject>  s         = GetBlankNodeList();
            Subject         subject   = innerElement.Parent.Subject;
            RDFUriReference predicate = innerElement.Uri;
            Node            o         = s.Count == 0 ? NilUri : s[0];

            AddTriple(outputGraph, subject, predicate, o);

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

            if (a != null)
            {
                RDFUriReference i = Production.Resolve(innerElement, ("#" + a.StringValue));
                Production.Reify(subject, predicate, o, i, outputGraph);
            }


            //For each event n in s and the corresponding element event f in l, the following statement is added to the graph:
            //n.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> f.string-value .
            //For each consecutive and overlapping pair of events (n, o) in s, the following statement is added to the graph:
            //n.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> o.string-value .
            //If s is not empty, n is the last event identifier in s, the following statement is added to the graph:
            //n.string-value <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
            int index = 0;

            foreach (EventElement f in innerElement.Children)
            {
                AddTriple(outputGraph, s[index], FirstUri, f.Subject);

                //If next element is available
                if (index < (s.Count - 1))
                {
                    AddTriple(outputGraph, s[index], RestUri, s[index + 1]);
                }
                else
                {
                    AddTriple(outputGraph, s[index], RestUri, NilUri);
                }

                index++;
            }
        }
Esempio 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);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Determines whether id is already defined in specified output graph.
        /// </summary>
        /// <param name="outputGraph">The output graph.</param>
        /// <returns>
        ///     <c>true</c> if id is already defined in the specified output graph; otherwise, <c>false</c>.
        /// </returns>
        private bool IsIdAlreadyDefined(Graph outputGraph)
        {
            //TODO: Revisit the logic
            RDFUriReference idUri = Production.Resolve(innerAttribute.Parent, "#" + innerAttribute.StringValue);

            if (outputGraph.Where(tuple => (tuple.TripleSubject as RDFUriReference) == idUri).Count() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <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);
            }
        }
        /// <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);
                }
            }
        }