/// <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> 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); } }
/// <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 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++; } }
/// <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); } } }