示例#1
0
    def __init__(self, configuration):
        #---------------------------------
        """
    Reads and parses configuration information.

    Configuration includes location of RDF store.
    """

        self.rdfstore = Virtuoso('http://localhost:8890')

        self._propdata = {
            'Text':
            PropertyValue('bif:contains', [Relation('contains', 'text_word')],
                          'text'),
            'Tagged':
            PropertyValue('bsml:tag', [
                Relation('has tag', 'uri_match'),
                Relation('not tagged', 'uri_nomatch')
            ], 'list'),
            'Event':
            PropertyValue('bsml:eventType', [
                Relation('has type', 'uri_match'),
                Relation('not type', 'uri_nomatch')
            ], 'list'),
            'Duration':
            PropertyValue(
                'tl:duration', ['=', '!=', '<', '<=', '>', '>='],
                'text'),  ## Needs ?res bsml:time ?tm . ?tm tl:duration "value"
            'Recording':
            PropertyValue('bsml:recording',
                          [Relation('with URI', 'uri_match')], 'text'),
            'Database':
            PropertyValue('bsml:database', [Relation('with URI', 'uri_match')],
                          'text'),
        }

        self._propvalues = {}
        for key, pv in self._propdata.iteritems():
            if pv.valuetype == 'list':
                values = []
                for r in self.rdfstore.select(
                        '?value ?label',
                        '[] %(uri)s ?value . optional { ?value rdfs:label ?label }',
                        ## prefixes=prefixes,
                        params=dict(uri=pv.uri)):
                    if r['value'].get('label'):
                        values.append(r['value']['label'])
                    else:
                        values.append(abbreviate_uri(r['value']['value']))


#        values = [ 'Normal beat', 'Fusion beat', 'Paced beat', 'PVC beat' ]  ###
                self._propvalues[key] = sorted(values)
示例#2
0
  def __init__(self, configuration):
  #---------------------------------
    """
    Reads and parses configuration information.

    Configuration includes location of RDF store.
    """

    self.rdfstore = Virtuoso('http://localhost:8890')

    self._propdata = {
      'Text': PropertyValue('bif:contains',
                            [ Relation('contains', 'text_word') ],
                            'text'),
      'Tagged': PropertyValue('bsml:tag',
                            [ Relation('has tag',    'uri_match'),
                              Relation('not tagged', 'uri_nomatch') ],
                            'list'),
      'Event': PropertyValue('bsml:eventType',
                            [ Relation('has type', 'uri_match'),
                              Relation('not type', 'uri_nomatch') ],
                            'list'),
      'Duration': PropertyValue('tl:duration',
                            ['=', '!=', '<', '<=', '>', '>='],
                            'text'),     ## Needs ?res bsml:time ?tm . ?tm tl:duration "value"
      'Recording': PropertyValue('bsml:recording',
                            [ Relation('with URI',  'uri_match') ],
                            'text'),
      'Database': PropertyValue('bsml:database',
                            [ Relation('with URI',  'uri_match') ],
                            'text'),
      }

    self._propvalues = { }
    for key, pv in self._propdata.iteritems():
      if pv.valuetype == 'list':
        values = [ ]
        for r in self.rdfstore.select('?value ?label',
                                      '[] %(uri)s ?value . optional { ?value rdfs:label ?label }',
                                      ## prefixes=prefixes,
                                      params=dict(uri=pv.uri)):
          if r['value'].get('label'): values.append(r['value']['label'])
          else:                       values.append(abbreviate_uri(r['value']['value']))
#        values = [ 'Normal beat', 'Fusion beat', 'Paced beat', 'PVC beat' ]  ###
        self._propvalues[key] = sorted(values)
from biosignalml.rdf.sparqlstore import StoreException, Virtuoso
from biosignalml.repository import BSMLStore


if __name__ == '__main__':
#=========================

  if len(sys.argv) < 2:
    print "Usage: %s recording_uri" % sys.argv[0]
    exit(1)

  recording = sys.argv[1]
  p = urlparse.urlparse(recording)
  repo = p.scheme + '://' + p.netloc

  store = Virtuoso('http://localhost:8890')

  for g in [ r['g']['value'] for r in json.loads(
               store.query("""select distinct ?g where {
                               graph <%s/provenance> {
                                ?g a bsml:RecordingGraph ;
                                   dct:subject <%s>
                                }
                              } order by ?g""" % (repo, recording),
                           format=Format.JSON,
                           prefixes={'bsml': BSML.prefix, 'dct': DCT.prefix})
               ).get('results', {}).get('bindings', [])
            ]:
    try:
      store.delete_graph(g)
    except StoreException:  ## Actual graph may not exist
示例#4
0
    [ 'db2',  1, 'db2', 'Database',  '',         ''   ],
    [ 'rec1', 2, 'rc1', 'Recording', 'duration', 1800 ],
    [ 'Signal', 3, 'r2/sg1', '',    'rdfs:label',    'V5' ],
    [ 'Signal', 3, 'sg2',    '',    'rdfs:label',    'V1' ],
    [ 'Event', 3, 'ev1', 'pvcBeat',  'count',         4   ],
    [ 'db',   1, 'db1', 'Database',  '',         ''   ],
    [ 'rec1', 2, 'rc1', 'Recording', 'duration', 1800 ],
    [ 'sig1', 3, 'sg1', 'Signal',    'label',    'V5' ],
    [ 'sig2', 3, 'sg2', 'Signal',    'label',    'V1' ],
    [ 'evt1', 3, 'ev1', 'Event',     'pvsBeat',   4   ],
    [ 'rec2', 2, 'rc2', 'Recording', 'duration', 1600 ],
   ]



  rdfstore = Virtuoso('http://localhost:8890')
  bsmlstore = BSMLStore('http://devel.biosignalml.org', rdfstore)

  PREFIXES = {
    'bsml': 'http://www.biosignalml.org/ontologies/2011/04/biosignalml#',
    'dct':  'http://purl.org/dc/terms/',
    'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
    'xsd':  'http://www.w3.org/2001/XMLSchema#',
    'pbank':	'http://www.biosignalml.org/ontologies/examples/physiobank#',

    'repo': 'http://devel.biosignalml.org/resource/',
    }

  def abbreviate(v):
  #-----------------
    for pfx, ns in PREFIXES.iteritems():
示例#5
0
import sys
import biosignalml.rdf as rdf
from biosignalml.rdf.sparqlstore import StoreException, Virtuoso


if __name__ == "__main__":
#=========================

  if len(sys.argv) < 3:
    print "Usage: %s store graph_uri" % sys.argv[0]
    exit(1)

  store = Virtuoso(sys.argv[1])
  try:
    store.delete_graph(sys.argv[2])
  except StoreException:  ## Actual graph may not exist
    pass
示例#6
0

if __name__ == "__main__":
#=========================

  import biosignalml.rdf as rdf
  from biosignalml.repository import BSMLStore
  from biosignalml.rdf.sparqlstore import Virtuoso
  from biosignalml.rdf.sparqlstore import get_result_value

  logging.basicConfig(format='%(asctime)s: %(message)s')
  logging.getLogger().setLevel('DEBUG')

  app = QtGui.QApplication(sys.argv)
  
  rdfstore = Virtuoso('http://localhost:8890')
  bsmlstore = BSMLStore('http://devel.biosignalml.org', rdfstore)

  PREFIXES = {
    'bsml': 'http://www.biosignalml.org/ontologies/2011/04/biosignalml#',
    'dct':  'http://purl.org/dc/terms/',
    'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
    'xsd':  'http://www.w3.org/2001/XMLSchema#',
    'pbank':	'http://www.biosignalml.org/ontologies/examples/physiobank#',

    'repo': 'http://devel.biosignalml.org/resource/',
    }

  def abbreviate(v):
  #-----------------
    for pfx, ns in PREFIXES.iteritems():
示例#7
0
import sys
import biosignalml.rdf as rdf
from biosignalml.rdf.sparqlstore import Virtuoso


if __name__ == "__main__":
#=========================

  if len(sys.argv) < 4:
    print "Usage: %s store graph_uri graph_source [format]" % sys.argv[0]
    exit(1)
  if len(sys.argv) == 5: format = rdf.Format.format(sys.argv[4])
  else:                  format = rdf.Format.RDFXML

  store = Virtuoso(sys.argv[1])
  graph = rdf.Graph.create_from_resource(rdf.Uri(sys.argv[3]), format, base=rdf.Uri(sys.argv[3]))
  ##print graph.serialise(format=rdf.Format.TURTLE)
  store.extend_graph(sys.argv[2], graph.serialise(format=rdf.Format.RDFXML), format=rdf.Format.RDFXML)
import sys
import biosignalml.rdf as rdf
from biosignalml.rdf.sparqlstore import StoreException, Virtuoso

if __name__ == "__main__":
    #=========================

    if len(sys.argv) < 3:
        print "Usage: %s store graph_uri" % sys.argv[0]
        exit(1)

    store = Virtuoso(sys.argv[1])
    try:
        store.delete_graph(sys.argv[2])
    except StoreException:  ## Actual graph may not exist
        pass
示例#9
0

if __name__ == "__main__":
    #=========================

    import biosignalml.rdf as rdf
    from biosignalml.repository import BSMLStore
    from biosignalml.rdf.sparqlstore import Virtuoso
    from biosignalml.rdf.sparqlstore import get_result_value

    logging.basicConfig(format='%(asctime)s: %(message)s')
    logging.getLogger().setLevel('DEBUG')

    app = QtGui.QApplication(sys.argv)

    rdfstore = Virtuoso('http://localhost:8890')
    bsmlstore = BSMLStore('http://devel.biosignalml.org', rdfstore)

    PREFIXES = {
        'bsml': 'http://www.biosignalml.org/ontologies/2011/04/biosignalml#',
        'dct': 'http://purl.org/dc/terms/',
        'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
        'xsd': 'http://www.w3.org/2001/XMLSchema#',
        'pbank': 'http://www.biosignalml.org/ontologies/examples/physiobank#',
        'repo': 'http://devel.biosignalml.org/resource/',
    }

    def abbreviate(v):
        #-----------------
        for pfx, ns in PREFIXES.iteritems():
            if v.startswith(ns): return '%s:%s' % (pfx, v[len(ns):])
示例#10
0
    query_results = [
        # Each row has [ reslabel, reslevel, resuri, type, prop, value ]
        ['db2', 1, 'db2', 'Database', '', ''],
        ['rec1', 2, 'rc1', 'Recording', 'duration', 1800],
        ['Signal', 3, 'r2/sg1', '', 'rdfs:label', 'V5'],
        ['Signal', 3, 'sg2', '', 'rdfs:label', 'V1'],
        ['Event', 3, 'ev1', 'pvcBeat', 'count', 4],
        ['db', 1, 'db1', 'Database', '', ''],
        ['rec1', 2, 'rc1', 'Recording', 'duration', 1800],
        ['sig1', 3, 'sg1', 'Signal', 'label', 'V5'],
        ['sig2', 3, 'sg2', 'Signal', 'label', 'V1'],
        ['evt1', 3, 'ev1', 'Event', 'pvsBeat', 4],
        ['rec2', 2, 'rc2', 'Recording', 'duration', 1600],
    ]

    rdfstore = Virtuoso('http://localhost:8890')
    bsmlstore = BSMLStore('http://devel.biosignalml.org', rdfstore)

    PREFIXES = {
        'bsml': 'http://www.biosignalml.org/ontologies/2011/04/biosignalml#',
        'dct': 'http://purl.org/dc/terms/',
        'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
        'xsd': 'http://www.w3.org/2001/XMLSchema#',
        'pbank': 'http://www.biosignalml.org/ontologies/examples/physiobank#',
        'repo': 'http://devel.biosignalml.org/resource/',
    }

    def abbreviate(v):
        #-----------------
        for pfx, ns in PREFIXES.iteritems():
            if v.startswith(ns): return '%s:%s' % (pfx, v[len(ns):])
from biosignalml.rdf import Format, DCT, PRV
from biosignalml.rdf.sparqlstore import StoreException, Virtuoso
from biosignalml.repository import BSMLStore

if __name__ == '__main__':
    #=========================

    if len(sys.argv) < 2:
        print "Usage: %s recording_uri" % sys.argv[0]
        exit(1)

    recording = sys.argv[1]
    p = urlparse.urlparse(recording)
    repo = p.scheme + '://' + p.netloc

    store = Virtuoso('http://localhost:8890')

    for g in [
            r['g']['value'] for r in json.loads(
                store.query("""select distinct ?g where {
                               graph <%s/provenance> {
                                ?g a bsml:RecordingGraph ;
                                   dct:subject <%s>
                                }
                              } order by ?g""" % (repo, recording),
                            format=Format.JSON,
                            prefixes={
                                'bsml': BSML.prefix,
                                'dct': DCT.prefix
                            })).get('results', {}).get('bindings', [])
    ]:
示例#12
0
from biosignalml.repository import BSMLUpdateStore

if __name__ == '__main__':
    #=========================

    logging.basicConfig(format='%(asctime)s: %(message)s')
    logging.getLogger().setLevel('DEBUG')

    if len(sys.argv) < 3:
        print "Usage: %s REPOSITORY_URI BIOSIGNALML_HDF5_FILE" % sys.argv[0]
        sys.exit(1)

    store = BSMLUpdateStore(
        sys.argv[1],
        #                     FourStore('http://localhost:8083'))
        Virtuoso('http://localhost:8890'))

    rec = H5Recording.open(sys.argv[2])

    statements, format = rec.get_metadata()
    if statements is None: raise ValueError("No metadata in source file")

    # rec.dataset = ....  From repo? Parameter?? Default to filename's full path??
    #                     Move/rename/copy file ??
    dataset = rdf.Uri('file://' + os.path.abspath(sys.argv[2]))

    graph = rdf.Graph.create_from_string(rec.uri, statements, format)
    graph.set_subject_property(rec.uri, BSML.dataset, dataset)

    graph_uri = store.add_recording_graph(
        rec.uri, graph.serialise(), 'file://' + os.path.abspath(__file__))
示例#13
0
  if len(sys.argv) < 2:
    print "Usage: %s repository" % sys.argv[0]
    exit(1)

  repo = sys.argv[1]

  print "***"
  print "*** This utility will remove all BioSignalML content from the repository at %s ***" % repo
  print "***"
  print "*** Are your sure? [NO/yes]"
  if sys.stdin.readline() != "yes\n": sys.exit(1)
  print "***"
  print "*** Are your *really* sure? [NO/yes]"
  if sys.stdin.readline() != "yes\n": sys.exit(1)

  store = Virtuoso('http://localhost:8890')

  for g in [ r['g']['value'] for r in json.loads(
               store.query("""select distinct ?g where {
                               graph <%s/provenance> {
                                ?g a bsml:RecordingGraph
                                }
                              } order by ?g""" % repo,
                            format=Format.JSON,
                            prefixes={'bsml': BSML.prefix})
               ).get('results', {}).get('bindings', [])
            ]:
    try:
      store.delete_graph(g)
    except StoreException:  ## Actual graph may not exist
      pass