dotgnu-libs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-libs-commits] CVS: dotgnu.rdf RdfParser_N3.cs,NONE,1.1 ChangeLo


From: Adam Ballai <address@hidden>
Subject: [Dotgnu-libs-commits] CVS: dotgnu.rdf RdfParser_N3.cs,NONE,1.1 ChangeLog,1.11,1.12 DotGNU.Rdf.build,1.7,1.8 RdfParser.cs,1.4,1.5 RdfParser_SystemXml.cs,1.2,1.3 RdfTriple.cs,1.1,1.2
Date: Sun, 16 Feb 2003 11:05:34 -0500

Update of /cvsroot/dotgnu-libs/dotgnu.rdf
In directory subversions:/tmp/cvs-serv20964

Modified Files:
        ChangeLog DotGNU.Rdf.build RdfParser.cs RdfParser_SystemXml.cs 
        RdfTriple.cs 
Added Files:
        RdfParser_N3.cs 
Log Message:


--- NEW FILE ---
/*
 * RDFParser_N3.cs - Implementation of the "DotGNU.Rdf.RdfParser_N3" class.
 *
 * Copyright (C) 2003  Adam Ballai, Cannibutter Software.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Thanks to Redland http://www.redland.opensource.ac.uk for the design 
interface.
 * 
 */

namespace DotGNU.Rdf
{
        using System;
        using System.IO;
        using System.Collections;
        using System.Text;

        public class RdfParser_N3 : RdfParser
        {

                private String str;                      // N3 string
                private int pos = 0;                     // tokenizer position
                private ArrayList vt = null;             // quantified 
variables table
                private RdfTriple r = null;                  // root RdfTriple 
object
                private String u = null;                 // base URI of the RDF 
resource

                internal const String ST = "{}[]()<>\"';,.^! \t\r\n\\";
                internal const String LOGa = "a";
                internal const String LOGe = "=";
                internal const String LOGi = "=>";
                internal const String LOGimplies = 
"<http://www.w3.org/2000/10/swap/log#implies>";
                internal const String LOGnotImplies = 
"<http://www.w3.org/2000/10/swap/log#notImplies>";
                internal const String DPO = 
"<http://www.daml.org/2001/03/daml+oil";;
                internal const String ONT = 
"<http://www.w3.org/2001/10/daml+oil";;
                internal const String OWL = "<http://www.w3.org/2002/07/owl";;
                internal const String OWLequivalentTo = 
"<http://www.w3.org/2002/07/owl#equivalentTo>";
                internal const String OWLsameIndividualAs = 
"<http://www.w3.org/2002/07/owl#sameIndividualAs>";
                internal const String OWLsameAs = 
"<http://www.w3.org/2002/07/owl#sameAs>";
                internal const String OWLsameClassAs = 
"<http://www.w3.org/2002/07/owl#sameClassAs>";
                internal const String OWLequivalentClass = 
"<http://www.w3.org/2002/07/owl#equivalentClass>";
                internal const String OWLsamePropertyAs = 
"<http://www.w3.org/2002/07/owl#samePropertyAs>";
                internal const String OWLequivalentProperty = 
"<http://www.w3.org/2002/07/owl#equivalentProperty>";
                internal const String OWLdifferentIndividualFrom = 
"<http://www.w3.org/2002/07/owl#differentIndividualFrom>";
                internal const String OWLdifferentFrom = 
"<http://www.w3.org/2002/07/owl#differentFrom>";
                internal const String OWLFunctionalProperty = 
"<http://www.w3.org/2002/07/owl#FunctionalProperty>";
                internal const String OWLInverseFunctionalProperty = 
"<http://www.w3.org/2002/07/owl#InverseFunctionalProperty>";
                internal const String OWLUnambiguousProperty = 
"<http://www.w3.org/2002/07/owl#UnambiguousProperty>";
                internal const String OWLUniqueProperty = 
"<http://www.w3.org/2002/07/owl#UniqueProperty>";
                internal const String XSDstring = 
"<http://www.w3.org/2001/XMLSchema#string>";
                internal const String RDFtype = 
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>";
                internal const String RDFList = 
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#List>";
                internal const String RDFfirst = 
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>";
                internal const String RDFrest = 
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>";
                internal const String RDFnil = 
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>";

                public RdfParser_N3() : base(null)
                {
                }
                
                // librdf_new_parser
                public RdfParser_N3(RdfWorld world, String name, String 
mime_type, RdfUri type_uri) : base(world)
                {
                }

                // RdfTriple interface
                public RdfParser_N3(String rk, ArrayList vt, RdfTriple triple, 
String baseUri) : base(null)
                {

                }
                
                // librdf_new_parser_from_factory
                public RdfParser_N3(RdfWorld world, RdfParserFactory 
parser_factory) : base(world)
                {
                }
                
                public virtual RdfTriple Parse()
                {
                        String nt = tokenize();
                        if (nt == null) 
                                return null;
                        return parse(true, nt);
                }
                
                public virtual RdfTriple Parse(String nt)
                {
                        return parse(false, nt);
                }

                internal RdfTriple parse(bool b, String nt) {
                        RdfTriple e = new RdfTriple();
                        try {
                                if (b) {
                                        if (nt == null) e.subj = null;
                                        else if (nt.Equals("{")) {
                                                nt = tokenize();
                                                if (nt.Equals(".")) e.subj = 
parse(false, "{}");
                                                else e.subj = parse(true, nt);
                                                RdfTriple el = e.subj;
                                                nt = tokenize();
                                                while (el.near != null) el = 
el.near;
                                                while (!nt.Equals("}")) {
                                                        el.near = parse(true, 
nt);
                                                        while (el.near != null) 
el = el.near;
                                                        nt = tokenize();
                                                }
                                        }
                                        else if (nt.Equals("[")) {
                                                e.subj = parse(true, null);
                                                if (e.subj.verb == null) r.verb 
= ";]";
                                                nt = tokenize();
                                                if (!nt.Equals("]")) 
Console.Error.WriteLine("** (p1) expecting ] at " + e + " but got " + nt);
                                        }
                                        else if (nt.Equals("(")) {
                                                list(e);
                                                e.subj = e.obj;
                                                e.obj = null;
                                        }
                                        else {
                                                e.subj = parse(false, nt);
                                                if (nt.Equals("this")) 
e.subj.verb = '<' + u + "#frag" + e.GetHashCode() + '>';
                                        }
                                        nt = tokenize();
                                }
                                if (nt == null || nt.Equals(";")) {
                                        e.bound = true;
                                        return e;
                                }
                                else if (e.subj != null && nt.StartsWith("_:")) 
{
                                        e.cverb = nt;
                                        if (!vt.Contains(nt)) vt.Add(nt);
                                }
                                else if (nt.Equals("[")) {
                                        String a = "_:" + e.GetHashCode();
                                        if (!vt.Contains(a)) vt.Add(a);
                                        RdfTriple ap = parse(true, a);
                                        e.cverb = a;
                                        if (ap.verb != null) r.verb = ";]";
                                        nt = tokenize();
                                        if (!nt.Equals("]")) 
Console.Error.WriteLine("** (p2) expecting ] at " + e + " but got " + nt);
                                        e.near = ap;
                                }
                                else if (nt.Equals("(")) {
                                        list(e);
                                        return e.obj;
                                }
                                else e.cverb = nt;
                                e.verb = e.cverb;
                                if (e.verb.EndsWith("@@")) e.verb = 
e.verb.Substring(0, e.verb.Length - 2);
                                String s1 = e.verb;
                                String s2 = "";

                                //      Console.Error.WriteLine("e.verb index 
of " + e.verb);   
                                if (e.verb.IndexOf('"') != -1) {
                                        s1 = e.verb.Substring(0, 
e.verb.IndexOf('"'));
                                        s2 = 
e.verb.Substring(e.verb.IndexOf('"'));
                                }
                                if (r != null && s1.Length > 0 && 
!s1.Equals(LOGa) && !s1.Equals(LOGe) &&
                                                s1[0] != '(' && s1[0] != '<' && 
s1[0] != '[' &&
                                                s1[0] != '_' && s1[0] != '"' && 
s1[0] != '\'' && s1.IndexOf(':') != - 1) {
                                        String pf = s1.Substring(0, 
s1.IndexOf(':') + 1);
                                        String pg = (String) r.nsp[pf];
                                        if (pg != null) pf = pg;
                                        String qf = (String) r.ns[pf];
                                        if (qf == null) {
                                                Console.Error.WriteLine("** no 
@prefix " + pf + " found, taking <" + u + "#>");
                                                qf = "<" + u + "#>";
                                                r.ns[pf] = qf;
                                        }
                                        StringBuilder sb = new 
StringBuilder(pf);

                                        //      
Console.Error.WriteLine("e.cverb.IndexOf " + e.cverb);  

                                        
sb.Append(e.cverb.Substring(e.cverb.IndexOf(':') + 1));
                                        e.cverb = sb.ToString();
                                        sb = new StringBuilder(qf);
                                        sb.Insert(sb.Length - 1, 
s1.Substring(s1.IndexOf(':') + 1));
                                        e.verb = sb.ToString() + s2;
                                }
                                else if (u != null && s1.Length > 0 && s1[0] == 
'<' && s1.IndexOf(':') == - 1)
                                        e.verb = e.cverb = '<' + 
toURI(s1.Substring(1, s1.Length - 2)) + '>' + s2;
                                if (e.verb.StartsWith("'")) e.verb = "'" + 
Double.Parse(e.verb.Substring(1, e.verb.Length - 2)) + "'";
                                if (e.verb.Equals(LOGa)) e.verb = RDFtype;
                                if (e.verb.Equals(LOGe)) e.verb = OWLsameAs;
                                if (e.verb.Equals(LOGi)) e.verb = LOGimplies;
                                if (e.verb.StartsWith(DPO)) e.verb = OWL + 
e.verb.Substring(DPO.Length);
                                if (e.verb.StartsWith(ONT)) e.verb = OWL + 
e.verb.Substring(ONT.Length);
                                if (e.verb.Equals(OWLequivalentTo)) e.verb = 
OWLsameAs;
                                if (e.verb.Equals(OWLsameIndividualAs)) e.verb 
= OWLsameAs;
                                if (e.verb.Equals(OWLsameClassAs)) e.verb = 
OWLequivalentClass;
                                if (e.verb.Equals(OWLsamePropertyAs)) e.verb = 
OWLequivalentProperty;
                                if (e.verb.Equals(OWLdifferentIndividualFrom)) 
e.verb = OWLdifferentFrom;
                                if (e.verb.Equals(OWLUnambiguousProperty)) 
e.verb = OWLInverseFunctionalProperty;
                                if (e.verb.Equals(OWLUniqueProperty)) e.verb = 
OWLFunctionalProperty;
                                if (e.verb.StartsWith("?") && 
!vt.Contains(e.verb)) vt.Add(e.verb);

                                if (vt != null)
                                {
                                        //       Console.Error.WriteLine("TODO: 
This broken");  
                                        //      Console.Error.WriteLine("count  
" + count);     
                                        int count = vt.Count;


                                        if (count > 0)
                                        {
                                                
Console.Error.WriteLine("e.varid = vt.IndexOf(e.verb); " + vt +":"+ e.verb);    
                                                e.varid = vt.IndexOf(e.verb);
                                        }
                                }       
                                if (e.varid == - 1) e.bound = true;
                                if (nt.Equals(".")) {
                                        e.obj = parse(false, "");
                                        e.verb = "";
                                        e.cverb = "";
                                        e.bound = true;
                                        return e;
                                }
                                if (str != null && pos < str.Length && str[pos] 
== '^' && str[pos + 1] == '^') {
                                        pos = pos + 2;
                                        RdfTriple et = parse(false, tokenize());
                                        if (!et.verb.Equals(XSDstring)) {
                                                e.subj = e.copy();
                                                e.verb = e.cverb = "^^";
                                                e.bound = true;
                                                e.obj = et;
                                                String.Intern(e.obj.verb);
                                                if (e.subj.bound) 
Datatype.Compare(e.obj.verb, r.getLit(e.subj), r.getLit(e.subj));
                                        }
                                }
                                if (b) {
                                        nt = tokenize();
                                        if (nt.Equals("{")) {
                                                nt = tokenize();
                                                if (nt.Equals(".")) e.obj = 
parse(false, "{}");
                                                else e.obj = parse(true, nt);
                                                RdfTriple el = e.obj;
                                                nt = tokenize();
                                                while (nt != null && 
!nt.Equals("}")) {
                                                        el.near = parse(true, 
nt);
                                                        el = el.near;
                                                        nt = tokenize();
                                                }
                                        }
                                        else if (nt.Equals("[")) {
                                                e.obj = parse(true, null);
                                                if (e.obj.verb != null) r.verb 
= ";]";
                                                nt = tokenize();
                                                if (!nt.Equals("]")) 
Console.Error.WriteLine("** (p3) expecting ] at " + e + " but got " + nt);
                                        }
                                        else if (nt.Equals("(")) list(e);
                                        else {
                                                e.obj = parse(false, nt);
                                                if 
(e.obj.verb.Equals(OWLFunctionalProperty)) r.mto[e.subj.verb] = r;
                                                if 
(e.obj.verb.Equals(OWLInverseFunctionalProperty)) r.otm[e.subj.verb] = r;
                                        }
                                        nt = tokenize();
                                        if (nt.EndsWith("\"\"\"")) {
                                                e.obj.cverb = e.obj.cverb + nt;
                                                e.obj.verb = e.obj.cverb;
                                                nt = tokenize();
                                        }
                                        RdfTriple el2 = e;
                                        while (nt.Equals(";") || 
nt.Equals(",")) {
                                                while (el2.near != null) el2 = 
el2.near;
                                                if (nt.Equals(";")) {
                                                        nt = tokenize();
                                                        if (nt.Equals("]")) {
                                                                r.verb = ";]";
                                                                nt = ";";
                                                                break;
                                                        }
                                                        else if 
(nt.Equals(".")) break;
                                                }
                                                else nt = el2.cverb;
                                                el2.near = parse(false, nt);
                                                el2.near.subj = e.subj;
                                                nt = tokenize();
                                                if (nt.Equals("{")) {
                                                        nt = tokenize();
                                                        if (nt.Equals(".")) 
el2.near.obj = parse(false, "{}");
                                                        else el2.near.obj = 
parse(true, nt);
                                                        RdfTriple ef = 
el2.near.obj;
                                                        nt = tokenize();
                                                        while (nt != null && 
!nt.Equals("}")) {
                                                                ef.near = 
parse(true, nt);
                                                                ef = ef.near;
                                                                nt = tokenize();
                                                        }
                                                }
                                                else if (nt.Equals("[")) {
                                                        el2.near.obj = 
parse(true, null);
                                                        if (el2.near.obj.verb 
!= null) r.verb = ";]";
                                                        nt = tokenize();
                                                        if (!nt.Equals("]")) 
Console.Error.WriteLine("** (p4) expecting ] at " + e + " but got " + nt);
                                                }
                                                else if (nt.Equals("(")) 
list(el2.near);
                                                else {
                                                        el2.near.obj = 
parse(false, nt);
                                                        if 
(el2.near.obj.verb.Equals(OWLFunctionalProperty)) r.mto[el2.near.subj.verb] = r;
                                                        if 
(el2.near.obj.verb.Equals(OWLInverseFunctionalProperty)) 
r.otm[el2.near.subj.verb] = r;
                                                }
                                                nt = tokenize();
                                                if (nt.EndsWith("\"\"\"")) {
                                                        el2.near.obj.cverb = 
el2.near.obj.cverb + nt;
                                                        el2.near.obj.verb = 
el2.near.obj.cverb;
                                                        nt = tokenize();
                                                }
                                                swap(el2.near);
                                        }
                                        if (!nt.Equals(".") && !nt.Equals(";"))
                                                Console.Error.WriteLine("** 
(p5) expecting . or ; at " + e + " but got " + nt);
                                }
                                swap(e);
                                e.far = r;
                                return e;
                        }
                        catch (NullReferenceException exc) {
                                Console.Error.WriteLine(exc.StackTrace);
                                return e;
                        }
                }

                internal String tokenize() {
                        String nt = token();
                        while (pos < str.Length && nt == null) nt = token();
                        return nt;
                }

                internal String next() {
                        int start = pos;

                        //    Console.Error.WriteLine("ST.IndexOf(str[pos]) " + 
ST + ":" +str[pos] );   

                        while (pos < str.Length && ST.IndexOf(str[pos]) < 0) {
                                pos++;
                                //      
Console.Error.WriteLine("ST.IndexOf(str[pos]) " + ST + ":" +str[pos] ); 
                        }       


                        if (start == pos && ST.IndexOf(str[pos]) >= 0) pos++;
                        return str.Substring(start, (pos) - (start));
                }

                internal String token() {
                        if (r.verb != null && r.verb.Equals(".}")) return 
r.verb = "}";
                        if (r.verb != null && r.verb.Equals(";]")) return 
r.verb = "]";
                        if (pos >= str.Length) return null;
                        int start = pos;
                        String t = null;
                        String nt = next();


                        //    Console.Error.WriteLine("nt.IndexOf #" + nt);

                        if (nt.IndexOf('#') != - 1) {
                                t = nt.Substring(0, nt.IndexOf('#'));
                                String v = r.verb;
                                while (nt != null && !nt.Equals("\n") && pos < 
str.Length) nt = next();
                                r.verb = v;
                                if (t.Equals("")) return null;
                        }
                        else if (nt.Equals("@prefix") || nt.Equals("bind")) {
                                String nsc = tokenize();
                                if (nsc.Equals("default")) nsc = ":";
                                String nsd = nsc;
                                String nsu = tokenize();

                                //          
Console.Error.WriteLine("nsu.IndexOf #" + nsu);

                                if (u != null && nsu.Length > 0 && nsu[0] == 
'<' && nsu.IndexOf(':') == - 1)
                                        nsu = '<' + toURI(nsu.Substring(1, 
nsu.Length - 2)) + '>';
                                String nsv = (String) r.ns[nsd];
                                while (nsv != null && !nsu.Equals(nsv)) {
                                        nsd = "ns" + nsd;
                                        nsv = (String) r.ns[nsd];
                                }
                                r.nsp[nsd] = nsd;
                                r.nsp[nsc] = nsd;
                                r.ns[nsd] = nsu;
                                tokenize();
                                return null;
                        }
                        else if (nt.Equals("\"")) {
                                StringBuilder sb = new StringBuilder("\"");
                                if (str[pos] == '"' && str[pos+1] == '"') {
                                        sb.Append(next());
                                        sb.Append(next());
                                        while (true) {
                                                sb.Append(next());
                                                if 
(sb.ToString().EndsWith("\"\"\"")) break;
                                        }
                                        t = sb.ToString();
                                }
                                else {
                                        nt = next();
                                        while (!nt.Equals("\"")) {
                                                if (nt.Equals("\\")) {
                                                        sb.Append(nt);
                                                        nt = next();
                                                }
                                                sb.Append(nt);
                                                if (pos >= str.Length) {
                                                        
Console.Error.WriteLine("** (t1) expecting \" at " + sb);
                                                        break;
                                                }
                                                nt = next();
                                        }
                                        sb.Append("\"");

                                        //          
Console.Error.WriteLine("-@" + str[pos]);

                                        if ("-@".IndexOf(str[pos]) != -1) 
sb.Append(token().ToLower());
                                        t = sb.ToString();
                                }
                        }
                        else if (nt.Equals("'")) {
                                StringBuilder sb = new StringBuilder("'");
                                nt = next();
                                while (!nt.Equals("'")) {
                                        sb.Append(nt);
                                        if (pos >= str.Length) {
                                                Console.Error.WriteLine("** 
(t2) expecting ' at " + sb);
                                                break;
                                        }
                                        nt = next();
                                }
                                t = sb.Append("'").ToString();
                        }
                        else if (nt.Equals("<")) {
                                StringBuilder sb = new StringBuilder("<");
                                nt = next();
                                while (!nt.Equals(">")) {
                                        sb.Append(nt);
                                        if (pos >= str.Length) {
                                                Console.Error.WriteLine("** 
(t2) expecting > at " + sb);
                                                break;
                                        }
                                        nt = next();
                                }
                                t = sb.Append(">").ToString();
                        }
                        else if (nt.Equals("=")) {
                                if (str[pos] == '>') t = nt + next();
                                else t = nt;
                        }
                        else if (nt.Equals("is")) {
                                t = tokenize();
                                nt = tokenize();
                                if (!nt.Equals("of")) 
Console.Error.WriteLine("** (t4) expecting \"of\" but got " + nt);
                                t = t + "@@";
                        }
                        else if (nt.Equals("has")) {
                                t = tokenize();
                                nt = tokenize();
                                if (!nt.Equals("of")) 
Console.Error.WriteLine("** (t5) expecting \"of\" but got " + nt);
                        }
                        else if (nt.Equals(" ") || nt.Equals("\t") || 
nt.Equals("\r") || nt.Equals("\n") ||
                                        nt.Equals("-") || nt.Equals(">"))
                                return null;
                        else if (nt.StartsWith("_:") && !nt.EndsWith("_" + 
RdfTriple.doc)) t = nt + "_" + RdfTriple.doc;
                        else t = nt;

                        //      Console.Error.WriteLine("ST . t " + ST + t);

                        if (pos < str.Length && ST.IndexOf(t) == -1 && t[0] != 
'"' && str[pos] == '"')
                                t = t + token();
                        if (pos < str.Length && str[pos] == '.') {
                                try {
                                        t = Int64.Parse(t) + next() + next();
                                }
                                catch (Exception) {
                                }
                        }
                        if (r.verb != null && t != null && !r.verb.Equals(".") 
&& t.Equals("}")) {
                                r.verb = ".}";
                                return ".";
                        }
                        if (r.verb != null && t != null && !r.verb.Equals(";") 
&& t.Equals("]")) {
                                r.verb = ";]";
                                return ";";
                        }
                        return r.verb = t;
                }

                internal void swap(RdfTriple e) {
                        if (e != null && e.subj == null && 
e.cverb.EndsWith("@@")) {
                                e.subj = e.obj;
                                e.obj = parse(false, e.cverb.Substring(0, 
e.cverb.Length - 2));
                                e.verb = e.cverb = "^^";
                        }
                        else if (e.subj != null && e.obj != null && 
e.cverb.EndsWith("@@")) {
                                RdfTriple el = e.subj;
                                e.subj = e.obj;
                                e.obj = el;
                                e.cverb = e.cverb.Substring(0, e.cverb.Length - 
2);
                        }
                }

                internal void list(RdfTriple e) {
                        RdfTriple el = e;
                        while (true) {
                                String nt = tokenize();
                                if (nt.StartsWith("@")) {
                                        el.obj = parse(false, '?' + 
nt.Substring(1));
                                        nt = tokenize();
                                        if (!nt.Equals(")")) 
Console.Error.WriteLine("** (p6) expecting ) at " + el + " but got " + nt);
                                        break;
                                }
                                else if (nt.Equals(")")) {
                                        el.obj = parse(false, RDFnil);
                                        break;
                                }
                                else el.obj = parse(false, RDFfirst);
                                if (nt.Equals("[")) {
                                        el.obj.obj = parse(true, null);
                                        tokenize();
                                }
                                else el.obj.obj = parse(false, nt);
                                el.obj.near = parse(false, RDFrest);
                                el.obj.near.near = parse(false, LOGa);      
                                el.obj.near.near.obj = parse(false, RDFList);
                                el = el.obj.near;
                        }
                }

                internal String toURI(String s) {
                        try {
                                s = new Uri(new Uri(u), s).ToString();
                        }
                        catch (Exception e) {
                                if (!u.StartsWith("file:")) 
Console.Error.WriteLine(u + " " + s + " " + e);
                        }
                        if (s.EndsWith(".n3#")) s = s.Substring(0, s.Length - 
4) + "#";
                        return s;
                }


                // *factory
                public delegate void Factory(RdfParserFactory parser_factory);

                // librdf_parser_register_factory
                public void ParserRegisterFactory(RdfWorld world, String name, 
String mime_type, String uri_string, Factory parser_factory)
                {
                        // do stuff
                }

                // librdf_get_parser_factory
                override public RdfParserFactory GetParserFactory(RdfWorld 
world, String name, String mime_type,  RdfUri type_uri)
                {
                        // TODO
                        return null;
                }



                // Parse


                // librdf_parser_parse_as_stream
                override public RdfStream ParserParseAsStream(RdfParser parser, 
RdfUri uri, RdfUri base_uri)
                {
                        // TODO
                        return null;
                }

                // librdf_parser_parse_into_model
                // non-zero on failure
                override  public int ParserParseIntoModel(RdfParser parser, 
RdfUri uri, RdfUri base_uri, RdfModel mode)
                {
                        // TODO 
                        return 0;
                }

                // librdf_init_parser
                override public void ParserInit(RdfWorld world)
                {
                        // TODO
                }

                // librdf_finish_parser
                override public void ParserFinish(RdfWorld world)
                {
                        // TODO 
                }

                // *error_fn
                public delegate void ErrorFn(IntPtr user_data, String msg, 
Object[] paramlist);

                // librdf_parser_set_error
                override public void ParserSetError(RdfParser parser, ErrorFn 
errorfn)
                {
                        // TODO
                }

                // *warning_fn
                public void WarningFn(IntPtr user_data, String msg, Object[] 
paramlist)
                {
                        // TODO
                }

                // librdf_parser_set_warning
                public override void ParserSetWarning(RdfParser parser, IntPtr 
user_data, WarningFn warningfn)
                {
                        // TODO
                }

                // librdf_parser_get_feature
                public override String Feature(RdfParser parser, RdfUri feature)
                {
                        // TODO:
                        return "Not Implemented";
                }


                // librdf_parser_set_feature
                // return non-zero on failure ... negative if no such feature
                public int Feature(RdfParser parser, RdfUri feature, String 
value)
                {

                        /*                      set 
                                                {
                        // TODO
                        }
                        */
                        return -1;
                }


        }

}


Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-libs/dotgnu.rdf/ChangeLog,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** ChangeLog   15 Feb 2003 18:42:09 -0000      1.11
--- ChangeLog   16 Feb 2003 16:05:31 -0000      1.12
***************
*** 1,3 ****
- 
  2003-02-15 18:41  Gopal.V  <address@hidden>
        
--- 1,2 ----

Index: DotGNU.Rdf.build
===================================================================
RCS file: /cvsroot/dotgnu-libs/dotgnu.rdf/DotGNU.Rdf.build,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** DotGNU.Rdf.build    15 Feb 2003 18:42:09 -0000      1.7
--- DotGNU.Rdf.build    16 Feb 2003 16:05:31 -0000      1.8
***************
*** 22,26 ****
--- 22,29 ----
                                <includes name="RdfSerializerN3.cs" />
                                <includes name="RdfTriple.cs" />
+                               <includes name="RdfParser_N3.cs" />
                                <includes name="FeatureTable.cs" />
+                               <includes name="Stack.cs" />
+                               <includes name="Datatypes.cs" />
                        </sources>
  

Index: RdfParser.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/dotgnu.rdf/RdfParser.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** RdfParser.cs        15 Feb 2003 13:35:42 -0000      1.4
--- RdfParser.cs        16 Feb 2003 16:05:31 -0000      1.5
***************
*** 29,32 ****
--- 29,34 ----
        public class RdfParser
        {
+               private RdfWorld world;
+               
                // *factory
                public  delegate void Factory(RdfParserFactory parser_factory);
***************
*** 37,50 ****
                // Constructor.
                // librdf_new_parser
!               extern public  RdfParser(RdfWorld world, 
                          String name,
                          String mime_type,
!                         RdfUri type_uri);
  
                // Constructor.
                // librdf_new_parser_from_factory
!               extern public RdfParser(RdfWorld world, RdfParserFactory 
parser_factory);
! 
  
  
                // librdf_get_parser_factory
--- 39,64 ----
                // Constructor.
                // librdf_new_parser
!               public  RdfParser(RdfWorld world, 
                          String name,
                          String mime_type,
!                         RdfUri type_uri)
!               {
!                       // TODO:
!                       this.world = world;
!               }
  
                // Constructor.
                // librdf_new_parser_from_factory
!               public RdfParser(RdfWorld world, RdfParserFactory 
parser_factory)
!               {
!                       // TODO:
!                       this.world = world;
!               }
  
+               public RdfParser(RdfWorld world)
+               {
+                       //TODO:
+                       this.world = world;
+               }
  
                // librdf_get_parser_factory

Index: RdfParser_SystemXml.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/dotgnu.rdf/RdfParser_SystemXml.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** RdfParser_SystemXml.cs      8 Feb 2003 18:35:07 -0000       1.2
--- RdfParser_SystemXml.cs      16 Feb 2003 16:05:31 -0000      1.3
***************
*** 1,4 ****
  /*
!  * RDFParser_SystemXml.cs - Implementation of the "DotGNU.Rdf.RdfNode" class.
   *
   * Copyright (C) 2003  Adam Ballai, Cannibutter Software.
--- 1,4 ----
  /*
!  * RDFParser_SystemXml.cs - Implementation of the 
"DotGNU.Rdf.RdfParser_SystemXml" class.
   *
   * Copyright (C) 2003  Adam Ballai, Cannibutter Software.

Index: RdfTriple.cs
===================================================================
RCS file: /cvsroot/dotgnu-libs/dotgnu.rdf/RdfTriple.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** RdfTriple.cs        15 Feb 2003 18:24:09 -0000      1.1
--- RdfTriple.cs        16 Feb 2003 16:05:31 -0000      1.2
***************
*** 25,29 ****
--- 25,34 ----
  {
        using System;
+       using System.IO;
+       using System.Text;
        using System.Net;
+       using System.Net.Sockets;
+       using System.Collections;
+       using System.Xml;
  
        public class RdfTriple
***************
*** 181,185 ****
                                if (!uri.StartsWith("data:")) loaded[baseURI] = 
this;
                                ArrayList vt = new ArrayList();
!                               Parser np = new Parser(rk, vt, this, u);
                                if (ns == null) {
                                        ns = new Hashtable();
--- 186,190 ----
                                if (!uri.StartsWith("data:")) loaded[baseURI] = 
this;
                                ArrayList vt = new ArrayList();
!                               RdfParser_N3 np = new RdfParser_N3(rk, vt, 
this, u);
                                if (ns == null) {
                                        ns = new Hashtable();
***************
*** 434,438 ****
                                String u = baseURI;
                                ArrayList vt = new ArrayList();
!                               Parser np = new Parser(cj, vt, this, u);
                                if (ns == null) {
                                        ns = new Hashtable();
--- 439,443 ----
                                String u = baseURI;
                                ArrayList vt = new ArrayList();
!                               RdfParser_N3 np = new RdfParser_N3(cj, vt, 
this, u);
                                if (ns == null) {
                                        ns = new Hashtable();
***************
*** 1094,1098 ****
                                                                        rk = 
this.Proof("data:," + nsp + g.ToString());
                                                                        vt = 
new ArrayList();
!                                                                       np = 
new Parser(rk, vt, this, u);
                                                                        el = 
np.Parse();
                                                                        
syno(el);
--- 1099,1103 ----
                                                                        rk = 
this.Proof("data:," + nsp + g.ToString());
                                                                        vt = 
new ArrayList();
!                                                                       np = 
new RdfParser_N3(rk, vt, this, u);
                                                                        el = 
np.Parse();
                                                                        
syno(el);
***************
*** 1377,1381 ****
                }
  
!               internal void skolem(bool otmp, RdfTriple ex, RdfTriple nr, 
Parser np, StringBuilder gen) {
                        if (ex.obj == null || ex.verb == "^^") return ;
                        RdfTriple el = ex.copy();
--- 1382,1386 ----
                }
  
!               internal void skolem(bool otmp, RdfTriple ex, RdfTriple nr, 
RdfParser_N3 np, StringBuilder gen) {
                        if (ex.obj == null || ex.verb == "^^") return ;
                        RdfTriple el = ex.copy();
***************
*** 1397,1401 ****
                }
  
!               internal void rewrite(RdfTriple el, Parser np) {
                        if (el.subj != null && el.subj.subj == null && 
el.subj.obj != null && el.subj.getFirst() == null) {
                                RdfTriple gr = el.subj.copy();
--- 1402,1406 ----
                }
  
!               internal void rewrite(RdfTriple el, RdfParser_N3 np) {
                        if (el.subj != null && el.subj.subj == null && 
el.subj.obj != null && el.subj.getFirst() == null) {
                                RdfTriple gr = el.subj.copy();
***************
*** 1765,1768 ****
--- 1770,1888 ----
                
  
+       }
+ 
+ 
+       internal class Datatype {
+               internal const String XSD = 
"<http://www.w3.org/2001/XMLSchema#";;
+               internal const String XSDduration = 
"<http://www.w3.org/2001/XMLSchema#duration>";
+               internal const String XSDdateTime = 
"<http://www.w3.org/2001/XMLSchema#dateTime>";
+               internal const String XSDtime = 
"<http://www.w3.org/2001/XMLSchema#time>";
+               internal const String XSDdate = 
"<http://www.w3.org/2001/XMLSchema#date>";
+               internal const String XSDgYearMonth = 
"<http://www.w3.org/2001/XMLSchema#gYearMonth>";
+               internal const String XSDgYear = 
"<http://www.w3.org/2001/XMLSchema#gYear>";
+               internal const String XSDgMonthDay = 
"<http://www.w3.org/2001/XMLSchema#gMonthDay>";
+               internal const String XSDgDay = 
"<http://www.w3.org/2001/XMLSchema#gDay>";
+               internal const String XSDgMonth = 
"<http://www.w3.org/2001/XMLSchema#gMonth>";
+               internal const String XSDstring = 
"<http://www.w3.org/2001/XMLSchema#string>";
+               internal const String XSDnormalizedString = 
"<http://www.w3.org/2001/XMLSchema#normalizedString>";
+               internal const String XSDtoken = 
"<http://www.w3.org/2001/XMLSchema#token>";
+               internal const String XSDlanguage = 
"<http://www.w3.org/2001/XMLSchema#language>";
+               internal const String XSDName = 
"<http://www.w3.org/2001/XMLSchema#Name>";
+               internal const String XSDNMTOKEN = 
"<http://www.w3.org/2001/XMLSchema#NMTOKEN>";
+               internal const String XSDNCName = 
"<http://www.w3.org/2001/XMLSchema#NCName>";
+               internal const String XSDID = 
"<http://www.w3.org/2001/XMLSchema#ID>";
+               internal const String XSDIDREF = 
"<http://www.w3.org/2001/XMLSchema#IDREF>";
+               internal const String XSDboolean = 
"<http://www.w3.org/2001/XMLSchema#boolean>";
+               internal const String XSDbase64Binary = 
"<http://www.w3.org/2001/XMLSchema#base64Binary>";
+               internal const String XSDhexBinary = 
"<http://www.w3.org/2001/XMLSchema#hexBinary>";
+               internal const String XSDfloat = 
"<http://www.w3.org/2001/XMLSchema#float>";
+               internal const String XSDdecimal = 
"<http://www.w3.org/2001/XMLSchema#decimal>";
+               internal const String XSDinteger = 
"<http://www.w3.org/2001/XMLSchema#integer>";
+               internal const String XSDnonPositiveInteger = 
"<http://www.w3.org/2001/XMLSchema#nonPositiveInteger>";
+               internal const String XSDlong = 
"<http://www.w3.org/2001/XMLSchema#long>";
+               internal const String XSDnonNegativeInteger = 
"<http://www.w3.org/2001/XMLSchema#nonNegativeInteger>";
+               internal const String XSDnegativeInteger = 
"<http://www.w3.org/2001/XMLSchema#negativeInteger>";
+               internal const String XSDint = 
"<http://www.w3.org/2001/XMLSchema#int>";
+               internal const String XSDunsignedLong = 
"<http://www.w3.org/2001/XMLSchema#unsignedLong>";
+               internal const String XSDpositiveInteger = 
"<http://www.w3.org/2001/XMLSchema#positiveInteger>";
+               internal const String XSDshort = 
"<http://www.w3.org/2001/XMLSchema#short>";
+               internal const String XSDunsignedInt = 
"<http://www.w3.org/2001/XMLSchema#unsignedInt>";
+               internal const String XSDbyte = 
"<http://www.w3.org/2001/XMLSchema#byte>";
+               internal const String XSDunsignedShort = 
"<http://www.w3.org/2001/XMLSchema#unsignedShort>";
+               internal const String XSDunsignedByte = 
"<http://www.w3.org/2001/XMLSchema#unsignedByte>";
+               internal const String XSDdouble = 
"<http://www.w3.org/2001/XMLSchema#double>";
+               internal const String XSDanyURI = 
"<http://www.w3.org/2001/XMLSchema#anyURI>";
+ 
+               internal static Hashtable num = null;
+ 
+               internal static bool IsNumeric(String dt) {
+                       if (num == null) {
+                               num = new Hashtable();
+                               num[XSDfloat] = new Object();
+                               num[XSDdouble] = new Object();
+                               num[XSDdecimal] = new Object();
+                               num[XSDinteger] = new Object();
+                               num[XSDnonPositiveInteger] = new Object();
+                               num[XSDlong] = new Object();
+                               num[XSDnonNegativeInteger] = new Object();
+                               num[XSDnegativeInteger] = new Object();
+                               num[XSDint] = new Object();
+                               num[XSDunsignedLong] = new Object();
+                               num[XSDpositiveInteger] = new Object();
+                               num[XSDshort] = new Object();
+                               num[XSDunsignedInt] = new Object();
+                               num[XSDbyte] = new Object();
+                               num[XSDunsignedShort] = new Object();
+                               num[XSDunsignedByte] = new Object();
+                       }
+                       return num[dt] != null;
+               }
+ 
+               internal static int Compare(String dt, String s1, String s2) {
+                       try {
+                               if (dt == XSDduration) return 
XmlConvert.ToTimeSpan(s1).CompareTo(XmlConvert.ToTimeSpan(s2));
+                               if (dt == XSDdateTime) return 
XmlConvert.ToDateTime(s1).CompareTo(XmlConvert.ToDateTime(s2));
+                               if (dt == XSDtime) return 
XmlConvert.ToDateTime(s1).CompareTo(XmlConvert.ToDateTime(s2));
+                               if (dt == XSDdate) return 
XmlConvert.ToDateTime(s1).CompareTo(XmlConvert.ToDateTime(s2));
+                               if (dt == XSDgYearMonth) return 
XmlConvert.ToDateTime(s1).CompareTo(XmlConvert.ToDateTime(s2));
+                               if (dt == XSDgYear) return 
XmlConvert.ToDateTime(s1).CompareTo(XmlConvert.ToDateTime(s2));
+                               if (dt == XSDgMonthDay) return 
XmlConvert.ToDateTime(s1).CompareTo(XmlConvert.ToDateTime(s2));
+                               if (dt == XSDgDay) return 
XmlConvert.ToDateTime(s1).CompareTo(XmlConvert.ToDateTime(s2));
+                               if (dt == XSDgMonth) return 
XmlConvert.ToDateTime(s1).CompareTo(XmlConvert.ToDateTime(s2));
+                               if (dt == XSDstring) return s1.CompareTo(s2);
+                               if (dt == XSDnormalizedString) return 
s1.CompareTo(s2);
+                               if (dt == XSDtoken) return s1.CompareTo(s2);
+                               if (dt == XSDlanguage) return s1.CompareTo(s2);
+                               if (dt == XSDName) return s1.CompareTo(s2);
+                               if (dt == XSDNMTOKEN) return s1.CompareTo(s2);
+                               if (dt == XSDNCName) return s1.CompareTo(s2);
+                               if (dt == XSDID) return s1.CompareTo(s2);
+                               if (dt == XSDIDREF) return s1.CompareTo(s2);
+                               if (dt == XSDboolean) return 
XmlConvert.ToBoolean(s1).CompareTo(XmlConvert.ToBoolean(s2));
+                               if (dt == XSDbase64Binary) return 
s1.CompareTo(s2);
+                               if (dt == XSDhexBinary) return s1.CompareTo(s2);
+                               if (dt == XSDfloat) return 
XmlConvert.ToSingle(s1).CompareTo(XmlConvert.ToSingle(s2));
+                               if (dt == XSDdecimal) return 
XmlConvert.ToDecimal(s1).CompareTo(XmlConvert.ToDecimal(s2));
+                               if (dt == XSDinteger) return 
XmlConvert.ToDecimal(s1).CompareTo(XmlConvert.ToDecimal(s2));
+                               if (dt == XSDnonPositiveInteger) return 
XmlConvert.ToDecimal(s1).CompareTo(XmlConvert.ToDecimal(s2));
+                               if (dt == XSDlong) return 
XmlConvert.ToInt64(s1).CompareTo(XmlConvert.ToInt64(s2));
+                               if (dt == XSDnonNegativeInteger) return 
XmlConvert.ToDecimal(s1).CompareTo(XmlConvert.ToDecimal(s2));
+                               if (dt == XSDnegativeInteger) return 
XmlConvert.ToDecimal(s1).CompareTo(XmlConvert.ToDecimal(s2));
+                               if (dt == XSDint) return 
XmlConvert.ToInt32(s1).CompareTo(XmlConvert.ToInt32(s2));
+                               if (dt == XSDunsignedLong) return 
XmlConvert.ToUInt64(s1).CompareTo(XmlConvert.ToUInt64(s2));
+                               if (dt == XSDpositiveInteger) return 
XmlConvert.ToDecimal(s1).CompareTo(XmlConvert.ToDecimal(s2));
+                               if (dt == XSDshort) return 
XmlConvert.ToInt16(s1).CompareTo(XmlConvert.ToInt16(s2));
+                               if (dt == XSDunsignedInt) return 
XmlConvert.ToUInt32(s1).CompareTo(XmlConvert.ToUInt32(s2));
+                               if (dt == XSDbyte) return 
XmlConvert.ToSByte(s1).CompareTo(XmlConvert.ToSByte(s2));
+                               if (dt == XSDunsignedShort) return 
XmlConvert.ToUInt16(s1).CompareTo(XmlConvert.ToUInt16(s2));
+                               if (dt == XSDunsignedByte) return 
XmlConvert.ToByte(s1).CompareTo(XmlConvert.ToByte(s2));
+                               if (dt == XSDdouble) return 
XmlConvert.ToDouble(s1).CompareTo(XmlConvert.ToDouble(s2));
+                               if (dt == XSDanyURI) return new 
Uri(s1).ToString().CompareTo(new Uri(s2).ToString());
+                               return s1.CompareTo(s2);
+                       }
+                       catch (Exception) {
+                               return s1.CompareTo(s2);
+                       }
+               }
        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]