Example #1
0
def doCommand(inputURI="/dev/stdin"):
    import sys
    global sax2rdf
    global kb
    import os

    # Load the data:

    progress("Data from", inputURI)
    kb = load(inputURI)
    #       print "# Size of kb: ", len(kb)

    totals = {}
    for s in kb.statements:
        obj = s.object()
        if isinstance(obj, Literal):
            try:
                value = float(obj.string)
            except:
                continue
            tot = totals.get(s.predicate(), 0) + value
            totals[s.predicate()] = tot

    ko = kb.newFormula()
    for pred in totals.keys():
        ko.add(subj=pred,
               pred=qu.total,
               obj=ko.newLiteral("%7.2f" % totals[pred]))
    print ko.close().n3String()
Example #2
0
def crawl(this):
    global agenda
    global already
    global successes
    uri = this.uriref()
    print
    print "<%s> a" % uri,
    try:
        f = load(uri)
    except:
        print ":Inaccessible."
        return
    print ":Accessible",
    successes = successes + 1
    thisd = getDoc(this)
    for s in f.statements:
        for p in 1, 2, 3:
            x = s[p]
            if isinstance(x, Fragment):
                r = x.resource
                if r not in thisd.mentions:
                    thisd.mentions.append(r)
                    print ";\n\t:mentionsSomethingIn <%s>" % r.uriref(),
                    if r not in agenda and r not in already:
                        agenda.append(r)
    print "."
Example #3
0
def doCommand(inputURI="/dev/stdin"):
        import sys
        global sax2rdf
        global kb
        import os

# Load the data:
         
        progress("Data from", inputURI)
        kb=load(inputURI)
#       print "# Size of kb: ", len(kb)

        totals = {}
        for s in kb.statements:
            obj = s.object()
            if isinstance(obj, Literal):
                try:
                    value = float(obj.string)
                except:
                    continue
                tot = totals.get(s.predicate(), 0) + value
                totals[s.predicate()] = tot

        ko = kb.newFormula()
        for pred in totals.keys():
            ko.add(subj=pred, pred=qu.total, obj=ko.newLiteral("%7.2f" % totals[pred]))
        print ko.close().n3String()
Example #4
0
def crawl(this):
    global agenda
    global already
    global successes
    uri = this.uriref()
    print
    print "<%s> a" % uri,
    try:
	f = load(uri)
    except:
	print ":Inaccessible."
	return
    print ":Accessible",
    successes = successes + 1
    thisd = getDoc(this)
    for s in f.statements:
	for p in 1,2,3:
	    x = s[p]
	    if isinstance(x, Fragment):
		r = x.resource
		if r not in thisd.mentions:
		    thisd.mentions.append(r)
		    print   ";\n\t:mentionsSomethingIn <%s>" % r.uriref(),
		    if r not in agenda and r not in already:
			agenda.append(r)
    print "."
Example #5
0
		if m == None:
		    raise SyntaxError("Token: should match %s\n\t" % 
				(rexp.pattern, parser.around(str, this)))
#		print u"Token matched to <%s> as pattern <%s>" % (str[this:m.end()], rexp.pattern)
		next = m.end()
	    tok, this = parser.token(str, next)  # Next token
	return tok, this

############################### Test Program

# The Grammar formula

grammarFile = argv[1].split("#")[0]
print "Loading", grammarFile
start = clock()
g = load(grammarFile)
taken = clock() - start
print "Loaded %i statements in %fs, ie %f/s." % (len(g), taken, len(g)/taken)

document = g.newSymbol(argv[2])

BNF = Namespace("http://www.w3.org/2000/10/swap/grammar/bnf#")
#RDF = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")

already = []
agenda = []
errors = []
doProduction(document)
while agenda:
    x = agenda[0]
    agenda = agenda[1:]
Example #6
0
                    raise SyntaxError("Token: should match %s\n\t" %
                                      (rexp.pattern, parser.around(str, this)))
#		print u"Token matched to <%s> as pattern <%s>" % (str[this:m.end()], rexp.pattern)
                next = m.end()
            tok, this = parser.token(str, next)  # Next token
        return tok, this


############################### Test Program

# The Grammar formula

grammarFile = argv[1].split("#")[0]
print "Loading", grammarFile
start = clock()
g = load(grammarFile)
taken = clock() - start
print "Loaded %i statements in %fs, ie %f/s." % (len(g), taken, len(g) / taken)

document = g.newSymbol(argv[2])

BNF = Namespace("http://www.w3.org/2000/10/swap/grammar/bnf#")
#RDF = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")

already = []
agenda = []
errors = []
doProduction(document)
while agenda:
    x = agenda[0]
    agenda = agenda[1:]