private RDFTerm finishStringLiteral(string str) { int mark = input.setHardMark(); int ch = input.read(); if (ch == '@') { return(RDFTerm.fromLangString(str, readLanguageTag())); } else if (ch == '^' && input.read() == '^') { ch = input.read(); if (ch == '<') { return(RDFTerm.fromTypedString(str, readIriReference())); } else { throw new ParserException(); } } else { input.setMarkPosition(mark); return(RDFTerm.fromTypedString(str)); } }
private void setObject(RDFTerm _object) { if ((_object) == null) { throw new ArgumentNullException("object"); } this._object = _object; }
public static RDFTerm fromBlankNode(string name) { if((name)==null)throw new ArgumentNullException("name"); if((name).Length==0)throw new ArgumentException("name is empty."); RDFTerm ret=new RDFTerm(); ret.kind=BLANK; ret.typeOrLanguage=null; ret.value=name; return ret; }
private void setPredicate(RDFTerm predicate) { if ((predicate) == null) { throw new ArgumentNullException("predicate"); } if (!(predicate.getKind() == RDFTerm.IRI)) { throw new ArgumentException("doesn't satisfy predicate.kind==RDFTerm.IRI"); } this.predicate = predicate; }
public static RDFTerm fromIRI(string iri) { if ((iri) == null) { throw new ArgumentNullException("iri"); } RDFTerm ret = new RDFTerm(); ret.kind = IRI; ret.typeOrLanguage = null; ret.value = iri; return(ret); }
private void setSubject(RDFTerm subject) { if ((subject) == null) { throw new ArgumentNullException("subject"); } if (!(subject.getKind() == RDFTerm.IRI || subject.getKind() == RDFTerm.BLANK)) { throw new ArgumentException("doesn't satisfy subject.kind==RDFTerm.IRI || subject.kind==RDFTerm.BLANK"); } this.subject = subject; }
public static RDFTerm fromBlankNode(string name) { if ((name) == null) { throw new ArgumentNullException("name"); } if ((name).Length == 0) { throw new ArgumentException("name is empty."); } RDFTerm ret = new RDFTerm(); ret.kind = BLANK; ret.typeOrLanguage = null; ret.value = name; return(ret); }
public override sealed bool Equals(object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (GetType() != obj.GetType()) { return(false); } RDFTerm other = (RDFTerm)obj; if (kind != other.kind) { return(false); } if (typeOrLanguage == null) { if (other.typeOrLanguage != null) { return(false); } } else if (!typeOrLanguage.Equals(other.typeOrLanguage)) { return(false); } if (value == null) { if (other.value != null) { return(false); } } else if (!value.Equals(other.value)) { return(false); } return(true); }
public static RDFTerm fromTypedString(string str, string iri) { if ((str) == null) { throw new ArgumentNullException("str"); } if ((iri) == null) { throw new ArgumentNullException("iri"); } if ((iri).Length == 0) { throw new ArgumentException("iri is empty."); } RDFTerm ret = new RDFTerm(); ret.kind = TYPEDSTRING; ret.typeOrLanguage = iri; ret.value = str; return(ret); }
public static RDFTerm fromLangString(string str, string languageTag) { if ((str) == null) { throw new ArgumentNullException("str"); } if ((languageTag) == null) { throw new ArgumentNullException("languageTag"); } if ((languageTag).Length == 0) { throw new ArgumentException("languageTag is empty."); } RDFTerm ret = new RDFTerm(); ret.kind = LANGSTRING; ret.typeOrLanguage = languageTag; ret.value = str; return(ret); }
private RDFTerm readObject(bool acceptLiteral) { int ch = input.read(); if (ch < 0) { throw new ParserException(); } else if (ch == '<') { return(RDFTerm.fromIRI(readIriReference())); } else if (acceptLiteral && (ch == '\"')) // start of quote literal { string str = readStringLiteral(ch); return(finishStringLiteral(str)); } else if (ch == '_') // Blank Node Label { if (input.read() != ':') { throw new ParserException(); } string label = readBlankNodeLabel(); RDFTerm term = bnodeLabels[label]; if (term == null) { term = RDFTerm.fromBlankNode(label); bnodeLabels.Add(label, term); } return(term); } else { throw new ParserException(); } }
private RDFTriple readTriples() { int mark = input.setHardMark(); int ch = input.read(); #if DEBUG if (!((ch >= 0))) { throw new InvalidOperationException("ch>=0"); } #endif input.setMarkPosition(mark); RDFTerm subject = readObject(false); if (!skipWhitespace()) { throw new ParserException(); } if (input.read() != '<') { throw new ParserException(); } RDFTerm predicate = RDFTerm.fromIRI(readIriReference()); if (!skipWhitespace()) { throw new ParserException(); } RDFTerm obj = readObject(true); skipWhitespace(); if (input.read() != '.') { throw new ParserException(); } skipWhitespace(); RDFTriple ret = new RDFTriple(subject, predicate, obj); endOfLine(input.read()); return(ret); }
public RDFTriple(RDFTerm subject, RDFTerm predicate, RDFTerm _object) { setSubject(subject); setPredicate(predicate); setObject(_object); }
private void setPredicate(RDFTerm predicate) { if((predicate)==null)throw new ArgumentNullException("predicate"); if(!(predicate.getKind()==RDFTerm.IRI))throw new ArgumentException("doesn't satisfy predicate.kind==RDFTerm.IRI"); this.predicate = predicate; }
private void setSubject(RDFTerm subject) { if((subject)==null)throw new ArgumentNullException("subject"); if(!(subject.getKind()==RDFTerm.IRI || subject.getKind()==RDFTerm.BLANK))throw new ArgumentException("doesn't satisfy subject.kind==RDFTerm.IRI || subject.kind==RDFTerm.BLANK"); this.subject = subject; }
/* * Replaces certain blank nodes with blank nodes whose * names meet the N-Triples requirements * @param triples A set of RDF triples * @param bnodeLabels A mapping of blank node names * already allocated. This method will modify this * _object as needed to allocate new blank nodes. */ // internal static void replaceBlankNodes(ISet <RDFTriple> triples, IDictionary <string, RDFTerm> bnodeLabels) { if (bnodeLabels.Count == 0) { return; } IDictionary <string, RDFTerm> newBlankNodes = new PeterO.Support.LenientDictionary <string, RDFTerm>(); IList <RDFTriple[]> changedTriples = new List <RDFTriple[]>(); int[] nodeindex = new int[] { 0 }; foreach (var triple in triples) { bool changed = false; RDFTerm subj = triple.getSubject(); if (subj.getKind() == RDFTerm.BLANK) { string oldname = subj.getValue(); string newname = suggestBlankNodeName(oldname, nodeindex, bnodeLabels); if (!newname.Equals(oldname)) { RDFTerm newNode = newBlankNodes[oldname]; if (newNode == null) { newNode = RDFTerm.fromBlankNode(newname); bnodeLabels.Add(newname, newNode); newBlankNodes.Add(oldname, newNode); } subj = newNode; changed = true; } } RDFTerm obj = triple.getObject(); if (obj.getKind() == RDFTerm.BLANK) { string oldname = obj.getValue(); string newname = suggestBlankNodeName(oldname, nodeindex, bnodeLabels); if (!newname.Equals(oldname)) { RDFTerm newNode = newBlankNodes[oldname]; if (newNode == null) { newNode = RDFTerm.fromBlankNode(newname); bnodeLabels.Add(newname, newNode); newBlankNodes.Add(oldname, newNode); } obj = newNode; changed = true; } } if (changed) { RDFTriple[] newTriple = new RDFTriple[] { triple, new RDFTriple(subj, triple.getPredicate(), obj) }; changedTriples.Add(newTriple); } } foreach (var triple in changedTriples) { triples.Remove(triple[0]); triples.Add(triple[1]); } }
private void setObject(RDFTerm _object) { if((_object)==null)throw new ArgumentNullException("object"); this._object = _object; }
// Processes a subset of RDF/XML metadata // Doesn't implement RDF/XML completely private void miniRdfXml(IElement node, RDFa.EvalContext context, RDFTerm subject) { string language=context.language; foreach(var child in node.getChildNodes()){ IElement childElement=(child is IElement) ? ((IElement)child) : null; if(childElement==null) { continue; } if(node.getAttribute("xml:lang")!=null){ language=node.getAttribute("xml:lang"); } else { language=context.language; } if(childElement.getLocalName().Equals("Description") && RDF_NAMESPACE.Equals(childElement.getNamespaceURI())){ RDFTerm about=relativeResolve(childElement.getAttributeNS(RDF_NAMESPACE,"about")); //Console.WriteLine("about=%s [%s]",about,childElement.getAttribute("about")); if(about==null){ about=subject; if(about==null) { continue; } } foreach(var child2 in child.getChildNodes()){ IElement childElement2= ((child2 is IElement) ? ((IElement)child2) : null); if(childElement2==null) { continue; } miniRdfXmlChild(childElement2,about,language); } } else if(RDF_NAMESPACE.Equals(childElement.getNamespaceURI())) throw new NotSupportedException(); } }
public static RDFTerm fromTypedString(string str, string iri) { if((str)==null)throw new ArgumentNullException("str"); if((iri)==null)throw new ArgumentNullException("iri"); if((iri).Length==0)throw new ArgumentException("iri is empty."); RDFTerm ret=new RDFTerm(); ret.kind=TYPEDSTRING; ret.typeOrLanguage=iri; ret.value=str; return ret; }
public static RDFTerm fromLangString(string str, string languageTag) { if((str)==null)throw new ArgumentNullException("str"); if((languageTag)==null)throw new ArgumentNullException("languageTag"); if((languageTag).Length==0)throw new ArgumentException("languageTag is empty."); RDFTerm ret=new RDFTerm(); ret.kind=LANGSTRING; ret.typeOrLanguage=languageTag; ret.value=str; return ret; }
private void miniRdfXmlChild(IElement node, RDFTerm subject, string language) { string nsname=node.getNamespaceURI(); if(node.getAttribute("xml:lang")!=null){ language=node.getAttribute("xml:lang"); } string localname=node.getLocalName(); RDFTerm predicate=relativeResolve(nsname+localname); if(!hasNonTextChildNodes(node)){ string content=getTextNodeText(node); RDFTerm literal; if(!string.IsNullOrEmpty(language)){ literal=RDFTerm.fromLangString(content, language); } else { literal=RDFTerm.fromTypedString(content); } outputGraph.Add(new RDFTriple(subject,predicate,literal)); } else { string parseType=node.getAttributeNS(RDF_NAMESPACE, "parseType"); if("Literal".Equals(parseType)) throw new NotSupportedException(); RDFTerm blank=generateBlankNode(); context.language=language; miniRdfXml(node,context,blank); outputGraph.Add(new RDFTriple(subject,predicate,blank)); } }
public static RDFTerm fromIRI(string iri) { if((iri)==null)throw new ArgumentNullException("iri"); RDFTerm ret=new RDFTerm(); ret.kind=IRI; ret.typeOrLanguage=null; ret.value=iri; return ret; }