예제 #1
0
def loadFiles(files):
    graph = myStore.formula()
    graph.setClosureMode("e")  # Implement sameAs by smushing
    if verbose > 0: progress("Loading %s..." % files)
    graph = myStore.loadMany(files, openFormula=graph)
    if verbose > 0: progress("Loaded", graph)
    return graph
예제 #2
0
def _s2f(s, base):
    """make a formula from a string.

    Cribbed from llyn.BI_parsedAsN3
    should be part of the myStore API, no? yes. TODO

    >>> _s2f("<#sky> <#color> <#blue>.", "http://example/socrates")
    {sky color blue}

    ^ that test output depends on the way formulas print themselves.
    """
    # """ emacs python mode needs help

    import notation3
    graph = formula()
    graph.setClosureMode("e")  # Implement sameAs by smushing
    p = notation3.SinkParser(graph.store,
                             openFormula=graph,
                             baseURI=base,
                             thisDoc="data:@@some-formula-string")
    p.startDoc()
    p.feed(s)
    f = p.endDoc()
    f.close()
    bindings = {}
    for s in f.statementsMatching(pred=reason.representedBy):
        val, _, key = s.spo()
        bindings[key] = val
    return f.substitution(bindings)
예제 #3
0
파일: delta.py 프로젝트: Mchockalingam/swap
def loadFiles(files):
    graph = myStore.formula()
    graph.setClosureMode("e")    # Implement sameAs by smushing
    if verbose>0: progress("Loading %s..." % files)
    graph = myStore.loadMany(files, openFormula=graph)
    if verbose>0: progress("Loaded", graph)
    return graph
예제 #4
0
파일: check.py 프로젝트: Mchockalingam/swap
def _s2f(s, base):
    """make a formula from a string.

    Cribbed from llyn.BI_parsedAsN3
    should be part of the myStore API, no? yes. TODO

    >>> _s2f("<#sky> <#color> <#blue>.", "http://example/socrates")
    {sky color blue}

    ^ that test output depends on the way formulas print themselves.
    """
    # """ emacs python mode needs help

    import notation3
    graph = formula()
    graph.setClosureMode("e")    # Implement sameAs by smushing
    p = notation3.SinkParser(graph.store, openFormula=graph, baseURI=base,
                             thisDoc="data:@@some-formula-string")
    p.startDoc()
    p.feed(s)
    f = p.endDoc()
    f.close()
    bindings = {}
    for s in f.statementsMatching(pred=reason.representedBy):
        val, _, key = s.spo()
        bindings[key] = val
    return f.substitution(bindings)
예제 #5
0
def topLevelLoad(uri=None, flags=''):
    graph = formula()
    graph.setClosureMode("e")  # Implement sameAs by smushing
    graph = load(uri, flags=flags, openFormula=graph)
    bindings = {}
    for s in graph.statementsMatching(pred=reason.representedBy):
        val, _, key = s.spo()
        bindings[key] = val
    return graph.substitution(bindings)
예제 #6
0
파일: check.py 프로젝트: Mchockalingam/swap
def topLevelLoad(uri=None, flags=''):
        graph = formula()
        graph.setClosureMode("e")    # Implement sameAs by smushing
        graph = load(uri, flags=flags, openFormula=graph)
        bindings = {}
        for s in graph.statementsMatching(pred=reason.representedBy):
            val, _, key = s.spo()
            bindings[key] = val
        return graph.substitution(bindings)
예제 #7
0
def main():
    """The main function


    """ ### """
    try:
        opts, testFiles = getopt.getopt(sys.argv[1:], "hc:o:e:",
            ["help", "command=", "output=", "error="])
    except getopt.GetoptError:
        # print help information and exit:
        usage()
        sys.exit(2)
    errorFile = ',temp/__error.txt'   # was "/dev/null"
    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o in ("-c", "--command"):
            commandFile = a
        if o in ("-o", "--output"):
            outputFile = a
        if o in ("-e", "--error"):
            errorFile = a

    assert system("mkdir -p ,temp") == 0
    assert system("mkdir -p ,diffs") == 0

    testFiles = testFiles + [
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql1/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql2/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql3/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/syntax-sparql4/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/bnode-coreference/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/boolean-effective-value/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/bound/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/construct/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/distinct/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/expr-builtin/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/graph/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/open-world/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional-filter/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/regex/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/sort/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/triple-match/manifest.ttl',
        'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/type-promotion/manifest.ttl']
    kb = loadMany(testFiles, referer="")
    output = formula()
    testCwmSparql(kb, output, errorFile)
    output.close()
    output.store.dumpNested(output, ToN3(file(outputFile, 'w').write))
예제 #8
0
def sparqlResults2Turtle(resultURI):
    result = resultURI
#    result = urllib.urlopen(resultURI).read()
    mappings = parseSparqlResults(checkStore(), result)
    f = formula()
    bindingSet = f.newBlankNode()
    f.add(bindingSet, rdf.type, rs.ResultSet)
    if isinstance(mappings, bool):
        f.add(bindingSet, rs.boolean, f.store.intern(mappings))
    else:
        for binding in mappings:
            m = f.newBlankNode()
            f.add(bindingSet, rs.solution, m)
            for var, val in binding.items():
                f.add(bindingSet, rs.resultVariable, f.newLiteral(var))
                binding = f.newBlankNode()
                f.add(m, rs.binding, binding)
                f.add(binding, rs.value, val)
                f.add(binding, rs.variable, f.newLiteral(var))
    retVal = f.ntString()
    return retVal
예제 #9
0
def main():
    """The main function


    """ ### """
    try:
        opts, testFiles = getopt.getopt(sys.argv[1:], "hc:o:e:",
            ["help", "command=", "output=", "error="])
    except getopt.GetoptError:
        # print help information and exit:
        usage()
        sys.exit(2)
    errorFile = ',temp/__error.txt'   # was "/dev/null"
    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        if o in ("-c", "--command"):
            commandFile = a
        if o in ("-o", "--output"):
            outputFile = a
        if o in ("-e", "--error"):
            errorFile = a
    commands = [w[:-1] for w in file(commandFile, 'r')]

    assert system("mkdir -p ,temp") == 0
    assert system("mkdir -p ,diffs") == 0

    kb = loadMany(testFiles, referer="")
    z = 0
    for command in commands:
        output = formula()
        testParser(command, kb, output, errorFile)

        output.close()
        output.store.dumpNested(output, ToN3(file(outputFile+`z`, 'w').write))
        z = z+1
예제 #10
0
파일: sync.py 프로젝트: weyls/swap
def loadFiles(files):
    graph = myStore.formula()
    graph.setClosureMode("e")    # Implement sameAs by smushing
    graph = myStore.loadMany(files, openFormula=graph)
    if verbose: progress("Loaded", graph, graph.__class__)
    return graph
예제 #11
0
def doCommand(serialDevice=None, outputURI=None, doTracks=1, doWaypoints=1, verbose=0):

   if os.name == 'nt':
      if not serialDevice: serialDevice =  "com1"
      phys = Win32SerialLink(serialDevice)
   else:
      if not serialDevice:  serialDevice =  "/dev/ttyS0"
#      serialDevice =  "/dev/cu.USA19H191P1.1"
      phys = UnixSerialLink(serialDevice)
      
   gps = Garmin(phys)

   print "GPS Product ID: %d Descriptions: %s Software version: %2.2f" % \
         (gps.prod_id, gps.prod_descs, gps.soft_ver)


   f = formula() # Empty store of RDF data
   base = uripath.base()
   
   record = f.newBlankNode()
   f.add(record, RDF.type, GPS.Record)

   if doWaypoints:
        # show waypoints
        if verbose: print "Getting waypoints"
        wpts = gps.getWaypoints()
        for w in wpts:
            if verbose: progress(`w`)
            wpt = symbol(uripath.join(base, w.ident))
            f.add(record, GPS.waypoint, wpt)
            f.add(wpt, WGS.lat, obj=intern(degrees(w.slat)))
            f.add(wpt, WGS.long, obj=intern(degrees(w.slon)))


   if doTracks:
      # show track
      if verbose: print "Getting tracks"
      tracks = gps.getTracks()
      for t in tracks:
        track = f.newBlankNode()
        f.add(record, GPS.track, track)
        for p in t:
            if isinstance(p, TrackHdr):
                if verbose: progress(`p`)
                f.add(track, GPS.disp, intern(p.dspl))
                f.add(track, GPS.color, intern(p.color))
                f.add(track, GPS.trk_ident, intern(p.trk_ident))
            else:
                if verbose: progress(`p`)
                point = f.newBlankNode()
                f.add(track, GPS.trackpoint, point)
                f.add(point, WGS.lat, obj=intern(degrees(p.slat)))
                f.add(point, WGS.long, obj=intern(degrees(p.slon)))
#               if verbose: progress("    time=", p.time)
#                progress('p.time='+`p.time`) # @@
                if p.time == 0 or p.time == 0xffffffffL:
                    if verbose: progress("time=%8x, ignoring" % p.time)
                else:
                    f.add(point, WGS.time, obj=intern(isodate.fullString(TimeEpoch+p.time)))

   phys.f.close()  # Should really be done by the del() below, but isn't
   del(phys) # close serial link (?)
   f = f.close()
   if verbose:
        progress("Beginning output. You can disconnect the GPS now.")
   s = f.n3String(base=base, flags="d")   # Flag - no default prefix, preserve gps: prefix hint
   if outputURI != None:
        op = open(outputURI, "w")
        op.write(s)
        op.close()
   else:
        print s 
예제 #12
0
# test proof API
from swap import myStore, diag, why
from swap.myStore import formula, symbol

diag.tracking = 1
f = formula()
rea = why.Premise("because I said so")
pred = symbol("http://example.com/weather")
f.add("Boston", pred, "sunny", why=rea)
f.add("Chicago", pred, "snowy", why=rea)

rea = why.Premise("because CNN said so")
f.add("Fort Myers", pred, "stormy", why=rea)

f = f.close()
g = why.explainFormula(f)
print g.n3String()

예제 #13
0
def doCommand(serialDevice=None,
              outputURI=None,
              doTracks=1,
              doWaypoints=1,
              verbose=0):

    if os.name == 'nt':
        if not serialDevice: serialDevice = "com1"
        phys = Win32SerialLink(serialDevice)
    else:
        if not serialDevice: serialDevice = "/dev/ttyS0"
        #      serialDevice =  "/dev/cu.USA19H191P1.1"
        phys = UnixSerialLink(serialDevice)

    gps = Garmin(phys)

    print "GPS Product ID: %d Descriptions: %s Software version: %2.2f" % \
          (gps.prod_id, gps.prod_descs, gps.soft_ver)

    f = formula()  # Empty store of RDF data
    base = uripath.base()

    record = f.newBlankNode()
    f.add(record, RDF.type, GPS.Record)

    if doWaypoints:
        # show waypoints
        if verbose: print "Getting waypoints"
        wpts = gps.getWaypoints()
        for w in wpts:
            if verbose: progress( ` w `)
            wpt = symbol(uripath.join(base, w.ident))
            f.add(record, GPS.waypoint, wpt)
            f.add(wpt, WGS.lat, obj=intern(degrees(w.slat)))
            f.add(wpt, WGS.long, obj=intern(degrees(w.slon)))

    if doTracks:
        # show track
        if verbose: print "Getting tracks"
        tracks = gps.getTracks()
        for t in tracks:
            track = f.newBlankNode()
            f.add(record, GPS.track, track)
            for p in t:
                if isinstance(p, TrackHdr):
                    if verbose: progress( ` p `)
                    f.add(track, GPS.disp, intern(p.dspl))
                    f.add(track, GPS.color, intern(p.color))
                    f.add(track, GPS.trk_ident, intern(p.trk_ident))
                else:
                    if verbose: progress( ` p `)
                    point = f.newBlankNode()
                    f.add(track, GPS.trackpoint, point)
                    f.add(point, WGS.lat, obj=intern(degrees(p.slat)))
                    f.add(point, WGS.long, obj=intern(degrees(p.slon)))
                    #               if verbose: progress("    time=", p.time)
                    #                progress('p.time='+`p.time`) # @@
                    if p.time == 0 or p.time == 0xffffffffL:
                        if verbose: progress("time=%8x, ignoring" % p.time)
                    else:
                        f.add(point,
                              WGS.time,
                              obj=intern(isodate.fullString(TimeEpoch +
                                                            p.time)))

    phys.f.close()  # Should really be done by the del() below, but isn't
    del (phys)  # close serial link (?)
    f = f.close()
    if verbose:
        progress("Beginning output. You can disconnect the GPS now.")
    s = f.n3String(
        base=base,
        flags="d")  # Flag - no default prefix, preserve gps: prefix hint
    if outputURI != None:
        op = open(outputURI, "w")
        op.write(s)
        op.close()
    else:
        print s
예제 #14
0
파일: day.py 프로젝트: AwelEshetu/cwm
                t = str(f.the(subj=point, pred=WGS.time))
                la = str(f.the(subj=point, pred=WGS.lat))
                lo = str(f.the(subj=point, pred=WGS.long))
                events.append((t, "T", (la, lo)))

    events.sort(compareByTime)

    last = None
    n = len(events)

    if verbose:
        progress("First event:", ` events[0] `, "Last event:", ` events[n - 1] `)

    minla, maxla = 90.0, -90.0
    minlo, maxlo = 400.0, -400.0
    conclusions = formula()
    for i in range(n):
        dt, ty, da = events[i]
        if ty == "T":  # Trackpoint
            last = i
            (la, lo) = float(da[0]), float(da[1])
            if la < minla:
                minla = la
            if la > maxla:
                maxla = la
            if lo < minlo:
                minlo = lo
            if lo > maxlo:
                maxlo = lo
        elif ty == "P":
            ph, photo = da
예제 #15
0
파일: day.py 프로젝트: linkeddata/swap
        print "Total disance (m)", totalDistance
        print "Total time (s)", elapsed, elapsed / 60
        print "Average speed", totalDistance / elapsed, "m/s", totalDistance / elapsed * 3.6, "kph"

    events.sort(compareByTime)

    last = None
    n = len(events)

    if verbose:
        progress("First event:", ` events[0] `, "Last event:",
                 ` events[n - 1] `)

    minla, maxla = 90.0, -90.0
    minlo, maxlo = 400.0, -400.0
    conclusions = formula()
    for i in range(n):
        dt, ty, p = events[i]
        if ty == "T":  # Trackpoint
            last = i
            # (la, lo, ele) = float(da[0]), float(da[1]), da[2]
            if p.lat < minla: minla = p.lat
            if p.lat > maxla: maxla = p.lat
            if p.lon < minlo: minlo = p.lon
            if p.lon > maxlo: maxlo = p.lon
        elif ty == "P":
            ph, photo = p
            if last == None:
                progress("%s: Photo %s  before any trackpoints" % (dt, photo))
                continue
            j = i + 1