Пример #1
0
def getpropertyvalue(id, property):

    assert (globals.g.predicate_objects(id) <>
            []), 'User does not exist or does not have that property'

    if property == 'email':
        results = []
        emailnlist = ['email1', 'email2', 'email3']
        for p in emailnlist:
            results = results + globals.g.query(
                """
              SELECT ?id ?p ?value 
              WHERE {edocol:%s edocol:%s ?value . 
                     ?id ?p ?value .}""" % (id, p),
                initNs=globals.ns).serialize('python')

        output = []
        for row in results:
            if (row[0] == edocol[id]) and (row[1] == edocol['email1']):
                output = output + [row]
                break
        for row in results:
            if (row[0] == edocol[id]) and (row[1] == edocol['email2']):
                output = output + [row]
                break
        for row in results:
            if (row[0] == edocol[id]) and (row[1] == edocol['email3']):
                output = output + [row]
                break
        print output
        output = globals.parse_pyformat_many(output)
        print output
        output = output[0][2] + '@' + output[1][2] + '.' + output[2][2]

        #Write database
        globals.writedb()
        return output

    else:
        # find all info on property of user id
        results = globals.g.query("""
                  SELECT ?id ?p ?value 
                  WHERE {edocol:%s edocol:%s ?value . 
                         ?id ?p ?value .}""" % (id, property),
                                  initNs=globals.ns).serialize('python')

        output = []
        for row in results:
            if (row[0] == edocol[id]) and (row[1] == edocol[property]):
                output = output + [row]

        #Write database
        globals.writedb()
        return globals.parse_pyformat_many(globals.individual(output))
Пример #2
0
def getpropertyvalue(id, property):

  assert ( globals.g.predicate_objects(id) <> [] ), 'User does not exist or does not have that property'

  if property == 'email':
    results = []
    emailnlist = ['email1', 'email2', 'email3']
    for p in emailnlist:
      results = results + globals.g.query("""
              SELECT ?id ?p ?value 
              WHERE {edocol:%s edocol:%s ?value . 
                     ?id ?p ?value .}""" % (id, p), 
              initNs=globals.ns).serialize('python')
      
    output = []  
    for row in results:
      if (row[0] == edocol[id]) and (row[1] == edocol['email1']):
        output = output + [row]
        break
    for row in results:
      if (row[0] == edocol[id]) and (row[1] == edocol['email2']):
        output = output + [row]
        break
    for row in results:
      if (row[0] == edocol[id]) and (row[1] == edocol['email3']):
        output = output + [row]
        break
    print output 
    output = globals.parse_pyformat_many(output)
    print output
    output = output[0][2] + '@' + output[1][2] + '.' + output[2][2] 

    #Write database
    globals.writedb()
    return output
    
  else:
    # find all info on property of user id
    results = globals.g.query("""
                  SELECT ?id ?p ?value 
                  WHERE {edocol:%s edocol:%s ?value . 
                         ?id ?p ?value .}""" % (id, property), 
                  initNs=globals.ns).serialize('python')                                                                                  
  
    output = []
    for row in results:
      if (row[0] == edocol[id]) and (row[1] == edocol[property]):
        output = output + [row]
  
    #Write database
    globals.writedb()
    return globals.parse_pyformat_many(globals.individual(output))
Пример #3
0
def get(did):
  """ pre: a valid id
      return: a list containing [name, contents]
  """
  #print "received get request"
  #Get it's name and content
  #try:  

  results = globals.g.query( """
                SELECT ?p ?n
                WHERE { edodoc:%s ?p ?n . }""" % (did, ) , 
                initNs=globals.ns).serialize(format='python')
                  
  assert results <> [], 'Document does not exist'                               # is did an existing document?
  return globals.parse_pyformat_many(results)
Пример #4
0
def users(arg):

    # find all users with property value
    results = globals.g.query("""
                SELECT ?id ?p ?value 
                WHERE {?id edocol:%s edocol:%s  . 
                       ?id ?p ?value .}""" % (arg[0], arg[1]),
                              initNs=globals.ns).serialize('python')

    output = []
    for row in results:
        if (row[1] == edocol[arg[0]]) and (row[2] == edocol[arg[1]]):
            output = output + [row]

    return globals.parse_pyformat_many(globals.individual(output))
Пример #5
0
def users(arg):

  # find all users with property value
  results = globals.g.query("""
                SELECT ?id ?p ?value 
                WHERE {?id edocol:%s edocol:%s  . 
                       ?id ?p ?value .}""" % (arg[0], arg[1]), 
                initNs=globals.ns).serialize('python') 

  output = []
  for row in results:
    if (row[1] == edocol[arg[0]]) and (row[2] == edocol[arg[1]]):
      output = output + [row]   

  return globals.parse_pyformat_many(globals.individual(output)) 
Пример #6
0
def delete(id):		            
  
  # find all properties of user id
  targets = globals.g.query( """
                SELECT ?id ?p ?v 
                WHERE { edocol:%s ?p ?v .
                        ?id ?p ?v .}""" % id, 
                initNs=globals.ns).serialize('python')   
  
  # deletes all references from user (including all data) while leaving references to the id intact.   
  for row in targets:
    if row[0] == edocol[id]:
      globals.g.remove(row)
    
  #Write database
  globals.writedb()
  return globals.parse_pyformat_many(globals.individual(targets))
Пример #7
0
def getallinfo(id):

    # find all properties of user id
    targets = globals.g.query("""
                SELECT ?id ?p ?v 
                WHERE { edocol:%s ?p ?v .
                        ?id ?p ?v .}""" % id,
                              initNs=globals.ns).serialize(format='python')
    results = []

    for row in targets:
        if row[0] == edocol[id]:
            results = results + [row]

    #Write database
    globals.writedb()
    return globals.parse_pyformat_many(globals.individual(results))
Пример #8
0
def delete(id):

    # find all properties of user id
    targets = globals.g.query("""
                SELECT ?id ?p ?v 
                WHERE { edocol:%s ?p ?v .
                        ?id ?p ?v .}""" % id,
                              initNs=globals.ns).serialize('python')

    # deletes all references from user (including all data) while leaving references to the id intact.
    for row in targets:
        if row[0] == edocol[id]:
            globals.g.remove(row)

    #Write database
    globals.writedb()
    return globals.parse_pyformat_many(globals.individual(targets))
Пример #9
0
def getallinfo(id):   
  
  # find all properties of user id
  targets = globals.g.query( """
                SELECT ?id ?p ?v 
                WHERE { edocol:%s ?p ?v .
                        ?id ?p ?v .}""" % id, 
                initNs=globals.ns).serialize(format='python')                                                   
  results = []

  
  for row in targets:
    if row[0] == edocol[id]:
      results = results + [row]

  #Write database
  globals.writedb()
  return globals.parse_pyformat_many(globals.individual(results))
Пример #10
0
def get(tag):
  
  # find all triples about tag
  targets = globals.g.query( """
                SELECT ?s ?p ?v 
                WHERE { edocol:%s ?p ?v .
                        ?s ?p ?v .}""" % tag, 
                initNs=globals.ns).serialize('python')  
                
  targets = targets + globals.g.query( """
                SELECT ?s ?p ?v
                WHERE { ?s ?p edocol:%s .
                        ?s ?p ?v .}""" % tag, 
                initNs=globals.ns).serialize('python')  
  
  # get everything
  results = []
  for row in targets:
    if (row[0] == edocol[tag]) or (row[2] == edocol[tag]):
      results = results + [row]

  #Write database
  globals.writedb()
  return globals.parse_pyformat_many(globals.individual(results))
Пример #11
0
def delete(tag):
  
  # find all triples about tag
  targets = globals.g.query( """
                SELECT ?s ?p ?v 
                WHERE { edocol:%s ?p ?v .
                        ?s ?p ?v .}""" % tag, 
                initNs=globals.ns).serialize('python')  
                
  targets = targets + globals.g.query( """
                SELECT ?s ?p ?v
                WHERE { ?s ?p edocol:%s .
                        ?s ?p ?v .}""" % tag,
                initNs=globals.ns).serialize('python')  

  # delete everything
  for row in targets:
    if (row[0] == edocol[tag]) or (row[2] == edocol[tag]):
      globals.g.remove(row)
      print row

  #Write database
  globals.writedb()
  return globals.parse_pyformat_many(globals.individual(targets))