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));
            }
        }
Пример #2
0
 private void setObject(RDFTerm _object)
 {
     if ((_object) == null)
     {
         throw new ArgumentNullException("object");
     }
     this._object = _object;
 }
Пример #3
0
 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;
 }
Пример #4
0
 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;
 }
Пример #5
0
        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);
        }
Пример #6
0
 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;
 }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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();
            }
        }
Пример #12
0
        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);
        }
Пример #13
0
 public RDFTriple(RDFTerm subject, RDFTerm predicate, RDFTerm _object)
 {
     setSubject(subject);
     setPredicate(predicate);
     setObject(_object);
 }
Пример #14
0
 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;
 }
Пример #15
0
 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;
 }
Пример #16
0
        /*
         *  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]);
            }
        }
Пример #17
0
 private void setObject(RDFTerm _object)
 {
     if((_object)==null)throw new ArgumentNullException("object");
     this._object = _object;
 }
Пример #18
0
 public RDFTriple(RDFTerm subject, RDFTerm predicate, RDFTerm _object)
 {
     setSubject(subject);
     setPredicate(predicate);
     setObject(_object);
 }
Пример #19
0
 // 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();
     }
 }
Пример #20
0
 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;
 }
Пример #21
0
 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;
 }
Пример #22
0
 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));
     }
 }
Пример #23
0
 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;
 }