Example #1
0
def exportRDFGraph(mi):
    g = ConjunctiveGraph()
    bnodes = {}
    for NSName, NSuriStr in mi.namespaceBindings.iteritems():
        g.namespace_manager.bind(NSName, URIRef(NSuriStr))

    modelAttrs = [model.__dict__[c] for c in model.__dict__.keys()]
    knownTypes = dict([(c.classURI, c) for c in modelAttrs if hasattr(c, "classURI")])
    knownInstances = dict([(i.URI, i) for i in modelAttrs if hasattr(i, "URI")])

    # Assign blind nodes :
    for s in mi.MainIdx.values():
        if s.URI == None or isBlind(s):
            snode = BNode()
            bnodes[s.URI] = snode
        for propName, propSet in s._props.iteritems():
            for v in propSet:
                if type(v) not in propSet.Lits and isBlind(v):
                    if not bnodes.has_key(v.URI):
                        vnode = BNode()
                        bnodes[v.URI] = vnode

    for s in mi.MainIdx.values():
        if not hasattr(s, "classURI") or s.classURI not in knownTypes.keys():
            raise ExportException("Object " + str(s) + " has no classURI, or classURI is not known in the MO model.")
            # FIXME : Maybe use a Resource ?

        if s.URI == None or isBlind(s):
            snode = bnodes[s.URI]
        else:
            snode = URIRef(s.URI)

        g.add((snode, RDF.type, URIRef(s.classURI)))

        for propName, propSet in s._props.iteritems():
            for v in propSet:
                if not hasattr(propSet, "propertyURI"):
                    raise ExportException(
                        "Property " + str(propName) + " on object " + str(s) + " has no propertyURI !"
                    )

                if type(v) not in propSet.Lits:
                    if not hasattr(v, "URI"):
                        raise ExportException("Property value " + str(v) + " is not a Literal, but has no URI !")
                    if isBlind(v):
                        g.add((snode, URIRef(propSet.propertyURI), bnodes[v.URI]))
                    else:
                        g.add((snode, URIRef(propSet.propertyURI), URIRef(v.URI)))
                else:
                    g.add((snode, URIRef(propSet.propertyURI), Literal(v)))

        info("Added " + str(type(s)) + " @ " + str(snode))

    return g
 def fingerprint(self, filename):
     lookup = FPTrackLookup()
     debug("Considering " + filename)
     mi = lookup.fpFile(filename)
     if hasattr(mi, "TrackIdx") and len(mi.TrackIdx) > 0:
         if not isBlind(mi.TrackIdx.values()[0]):
             self.succeeded += 1
     return mi
Example #3
0
	def fingerprint(self, filename) :
		lookup = FPTrackLookup()
		debug("Considering "+filename)
		mi = lookup.fpFile(filename)
		if hasattr(mi, "TrackIdx") and len(mi.TrackIdx) > 0:
			if not isBlind(mi.TrackIdx.values()[0]):
				self.succeeded+=1
		return mi
Example #4
0
    if thisBar_i:
        thisBar_i.endsAtDuration = secondsToXSDDuration(t_secs)
    if i != None:
        print " terminating last interval"
        i.endsAtDuration = secondsToXSDDuration(t_secs)
        mi.add(i)

        # Extract extra info from audio file :
    if audiofilename != None:
        absaudiofilename = os.path.abspath(audiofilename)
        ac_module = __import__("gnat.AudioCollection", [], [], ["AudioCollection"])
        ac = ac_module.AudioCollection()
        cwd = os.getcwd()
        os.chdir("./gnat")  # so we can find genpuid etc.
        fp_mi = ac.fingerprint(absaudiofilename)
        if hasattr(fp_mi, "TrackIdx") and len(fp_mi.TrackIdx) > 0 and not isBlind(fp_mi.TrackIdx.values()[0]):
            print "Adding info from audiofile fingerprinting."
            for o in fp_mi.MainIdx.values():
                mi.add(o)
            if hasattr(fp_mi, "SignalIdx") and len(fp_mi.SignalIdx) > 0:
                fp_mi.SignalIdx.values()[0].time = sig_int = Interval()
                sig_int.label = "Whole signal interval"
                sig_int.beginsAtDuration = secondsToXSDDuration(0)
                sig_int.onTimeLine = tl
                mi.add(sig_int)
        else:
            print "Fingerprinting failed, trying metadata lookup..."
            md_mi = ac.metadata(absaudiofilename)
            if hasattr(md_mi, "TrackIdx") and len(md_mi.TrackIdx) > 0 and not isBlind(md_mi.TrackIdx.values()[0]):
                print "Adding info from audiofile metadata lookup."
                for o in md_mi.MainIdx.values():
Example #5
0
def exportRDFGraph(mi):
    g = ConjunctiveGraph()
    bnodes = {}
    for NSName, NSuriStr in mi.namespaceBindings.iteritems():
        g.namespace_manager.bind(NSName, URIRef(NSuriStr))

    modelAttrs = [model.__dict__[c] for c in model.__dict__.keys()]
    knownTypes = dict([(c.classURI, c) for c in modelAttrs
                       if hasattr(c, "classURI")])
    knownInstances = dict([(i.URI, i) for i in modelAttrs
                           if hasattr(i, "URI")])

    # Assign blind nodes :
    for s in mi.MainIdx.values():
        if s.URI == None or isBlind(s):
            snode = BNode()
            bnodes[s.URI] = snode
        for propName, propSet in s._props.iteritems():
            for v in propSet:
                if type(v) not in propSet.Lits and isBlind(v):
                    if not bnodes.has_key(v.URI):
                        vnode = BNode()
                        bnodes[v.URI] = vnode

    for s in mi.MainIdx.values():
        if not hasattr(s, "classURI") or s.classURI not in knownTypes.keys():
            raise ExportException(
                "Object " + str(s) +
                " has no classURI, or classURI is not known in the MO model.")
            # FIXME : Maybe use a Resource ?

        if s.URI == None or isBlind(s):
            snode = bnodes[s.URI]
        else:
            snode = URIRef(s.URI)

        g.add((snode, RDF.type, URIRef(s.classURI)))

        for propName, propSet in s._props.iteritems():
            for v in propSet:
                if not hasattr(propSet, "propertyURI"):
                    raise ExportException("Property " + str(propName) +
                                          " on object " + str(s) +
                                          " has no propertyURI !")

                if type(v) not in propSet.Lits:
                    if not hasattr(v, "URI"):
                        raise ExportException(
                            "Property value " + str(v) +
                            " is not a Literal, but has no URI !")
                    if isBlind(v):
                        g.add((snode, URIRef(propSet.propertyURI),
                               bnodes[v.URI]))
                    else:
                        g.add((snode, URIRef(propSet.propertyURI),
                               URIRef(v.URI)))
                else:
                    g.add((snode, URIRef(propSet.propertyURI), Literal(v)))

        info("Added " + str(type(s)) + " @ " + str(snode))

    return g