Пример #1
0
def remove(tag, documentid):
  
  globals.g.remove( (edocol[documentid], edocol["tagged"], edocol[tag]) )   # remove the tag

  #Write database
  globals.writedb()
  return True
Пример #2
0
def fromemail(email):  
 
  email1 = ''
  email2 = ''
  email3 = ''
  phase = 1
  
  for char in email:
    if phase == 3:
      if char == '.':
        assert False, 'email address cannot contain more than 1 dot.'
      else:
        email3 = email3 + char  
    if phase == 2:
      if char == '.':
        phase = 3
      else:
        email2 = email2 + char  
    if phase == 1:
      if char == '@':
        phase = 2
      else:
        email1 = email1 + char 
 
  # find all properties of user id
  target = globals.g.query( """
                SELECT ?id
                WHERE { ?id edocol:email1 edocol:%s .
                        ?id edocol:email2 edocol:%s .
                        ?id edocol:email3 edocol:%s .}""" % (email1, email2, email3), 
                initNs=globals.ns).serialize(format='python')  
 
  globals.writedb() 
  return globals.parse_pyformat_one(target)
Пример #3
0
def edit(did, name, content):
    """ pre: nonempty id, time, contributor 
      post: false if contributor notin whitelist
      a new version of the page, with the updated content/name attached to the document. 
  """
    # Initialisation

    # create a new version
    try:
        oldname = globals.g.query(
            """                                  
          SELECT ?name
          WHERE {edodoc:?did edodoc:name ?name .}""",
            initNs=globals.ns,
            initBindings={"?did": did},
        )  # Get original name
    except:
        oldname = ""

    if oldname != name:  # Add a new name, if appliable
        globals.g.set((edodoc[str(did)], edodoc["name"], Literal(name)))

    globals.g.set((edodoc[str(did)], edodoc["content"], Literal(content)))  # Add the content

    # Write database
    globals.writedb()
    return did
Пример #4
0
def fromemail(email):

    email1 = ''
    email2 = ''
    email3 = ''
    phase = 1

    for char in email:
        if phase == 3:
            if char == '.':
                assert False, 'email address cannot contain more than 1 dot.'
            else:
                email3 = email3 + char
        if phase == 2:
            if char == '.':
                phase = 3
            else:
                email2 = email2 + char
        if phase == 1:
            if char == '@':
                phase = 2
            else:
                email1 = email1 + char

    # find all properties of user id
    target = globals.g.query("""
                SELECT ?id
                WHERE { ?id edocol:email1 edocol:%s .
                        ?id edocol:email2 edocol:%s .
                        ?id edocol:email3 edocol:%s .}""" %
                             (email1, email2, email3),
                             initNs=globals.ns).serialize(format='python')

    globals.writedb()
    return globals.parse_pyformat_one(target)
Пример #5
0
def edit(did, name, content):
    """ pre: nonempty id, time, contributor 
      post: false if contributor notin whitelist
      a new version of the page, with the updated content/name attached to the document. 
  """
    #Initialisation

    # create a new version
    try:
        oldname = globals.g.query("""                                  
          SELECT ?name
          WHERE {edodoc:?did edodoc:name ?name .}""",
                                  initNs=globals.ns,
                                  initBindings={'?did':
                                                did})  # Get original name
    except:
        oldname = ""

    if (oldname != name):  # Add a new name, if appliable
        globals.g.set((edodoc[str(did)], edodoc['name'], Literal(name)))

    globals.g.set((edodoc[str(did)], edodoc['content'],
                   Literal(content)))  # Add the content

    #Write database
    globals.writedb()
    return did
Пример #6
0
def deletepropertyvalue(id, property):
                                                              
  for row in globals.g.objects(edocol[id], edocol[property]):
    globals.g.remove( (edocol[id], edocol[property], row) )  
    
  #Write database
  globals.writedb()
  return True 
Пример #7
0
def deletepropertyvalue(id, property):

    for row in globals.g.objects(edocol[id], edocol[property]):
        globals.g.remove((edocol[id], edocol[property], row))

    #Write database
    globals.writedb()
    return True
Пример #8
0
def tag(tag, documentid): 
  
  assert re.match("^[a-zA-Z]+$", tag), 'invalid tag: tag does not consist of only letters'
  
  globals.g.add( (edocol[documentid], edocol["tagged"], edocol[tag]) )   # tag the document

  #Write database
  globals.writedb()
  return True
Пример #9
0
def fromproperty(property, value):  
 
  # find all properties of user id
  target = globals.g.query( """
                SELECT ?id
                WHERE { ?id edocol:%s edocol:%s .}""" % (property, value), 
                initNs=globals.ns).serialize(format='python')  
 
  globals.writedb() 
  return globals.parse_pyformat_one(target)  
Пример #10
0
def fromproperty(property, value):

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

    globals.writedb()
    return globals.parse_pyformat_one(target)
Пример #11
0
def follow(id, tag):

  assert not (get(tag) == []), 'no such tag'
  
  # add new user
  globals.g.add( (edocol[id], edocol["followstag"], edocol[tag]) )   # follow the tag

  #Write database
  globals.writedb()
  return True
Пример #12
0
def add(tag):

  assert re.match("^[a-zA-Z]+$", tag), 'invalid tag: tag does not consist of only letters'
  
  assert get(tag) == [], 'tag already exists'
  
  globals.g.add( (edocol[tag], edocol["type"], edocol['tag']) )   # add the tag

  #Write database
  globals.writedb()
  return tag
Пример #13
0
def follow(follower_id, followed_id):

  assert (not (followed_id in getpropertyvalue(follower_id, 'follows'))), 'already following that user'
  assert (not follower_id == followed_id), 'what? you cannot follow yourself! that is crazy!'
  assert globals.g.predicate_objects(followed_id)<>[], 'the user which you are trying to follow does not exist'

  globals.g.add((edocol[follower_id], edocol["follows"], edocol[followed_id])) 
  
  #Write database
  globals.writedb()
  return True
Пример #14
0
def deletespecific(id, property, value):

    for entry in getpropertyvalue(id, property):
        if value in entry:
            assert True, 'no such value to delete'

    globals.g.remove((edocol[id], edocol[property], edocol[value]))

    #Write database
    globals.writedb()
    return True
Пример #15
0
def deletespecific(id, property, value):
      
  for entry in getpropertyvalue(id, property):
    if value in entry:
      assert True,'no such value to delete'  
      
  globals.g.remove( (edocol[id], edocol[property], edocol[value]) )  
    
  #Write database
  globals.writedb()
  return True 
Пример #16
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))
Пример #17
0
def addpropertyvalue(id, property, value):

  assert (not (value in getpropertyvalue(id, property))), 'already has that value for that property'

  assert not (property == 'email'), 'a user can have only one email address at a time. use "set_user_property_value" to change it'
  assert ((not (property == email1)) and (not (property == email2)) and (not (property == email3))), 'cannot set email# properties directly' 
 
  globals.g.add( (edocol[id], edocol[property], edocol[value]) )    
  
  #Write database
  globals.writedb()
  return True
Пример #18
0
def delete(did):
    """ pre: identifier van een page
      post: de page word verwijdert """

    ###################
    ## H4xx0rz
    ##################$

    # delete type
    target = globals.g.query(
        """
                SELECT ?v 
                WHERE { edodoc:%s edodoc:type ?v .}"""
        % (did,),
        initNs=globals.ns,
    ).serialize("python")
    print target
    globals.g.remove((edodoc[str(did)], edodoc["type"], target[0]))

    # delete type
    target = globals.g.query(
        """
                SELECT ?v 
                WHERE { edodoc:%s edodoc:owner ?v .}"""
        % (did,),
        initNs=globals.ns,
    ).serialize("python")
    globals.g.remove((edodoc[str(did)], edodoc["owner"], target[0]))

    # delete type
    target = globals.g.query(
        """
                SELECT ?v 
                WHERE { edodoc:%s edodoc:name ?v .}"""
        % (did,),
        initNs=globals.ns,
    ).serialize("python")
    globals.g.remove((edodoc[str(did)], edodoc["name"], target[0]))

    # delete type
    target = globals.g.query(
        """
                SELECT ?v 
                WHERE { edodoc:%s edodoc:content ?v .}"""
        % (did,),
        initNs=globals.ns,
    ).serialize("python")
    globals.g.remove((edodoc[str(did)], edodoc["content"], target[0]))

    # Write database
    globals.writedb()
    return True
Пример #19
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))
Пример #20
0
def follow(follower_id, followed_id):

    assert (not (followed_id in getpropertyvalue(
        follower_id, 'follows'))), 'already following that user'
    assert (not follower_id
            == followed_id), 'what? you cannot follow yourself! that is crazy!'
    assert globals.g.predicate_objects(
        followed_id
    ) <> [], 'the user which you are trying to follow does not exist'

    globals.g.add(
        (edocol[follower_id], edocol["follows"], edocol[followed_id]))

    #Write database
    globals.writedb()
    return True
Пример #21
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))
Пример #22
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))
Пример #23
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))
Пример #24
0
def addpropertyvalue(id, property, value):

    assert (not (value in getpropertyvalue(
        id, property))), 'already has that value for that property'

    assert not (
        property == 'email'
    ), 'a user can have only one email address at a time. use "set_user_property_value" to change it'
    assert (
        (not (property == email1)) and (not (property == email2)) and
        (not (property == email3))), 'cannot set email# properties directly'

    globals.g.add((edocol[id], edocol[property], edocol[value]))

    #Write database
    globals.writedb()
    return True
Пример #25
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))
Пример #26
0
def new(name, password, email):
    # add new user
    id = newuserid()

    email1 = ''
    email2 = ''
    email3 = ''
    phase = 1

    for char in email:
        if phase == 3:
            if char == '.':
                assert False, 'email address cannot contain more than 1 dot.'
            else:
                email3 = email3 + char
        if phase == 2:
            if char == '.':
                phase = 3
            else:
                email2 = email2 + char
        if phase == 1:
            if char == '@':
                phase = 2
            else:
                email1 = email1 + char

    assert (fromemail(email) == []), 'email address already in use'

    globals.g.add(
        (edocol[id], edocol["type"], edocol["person"]))  # add the person
    globals.g.add((edocol[id], edocol["name"], edocol[name]))  # add the name
    globals.g.add((edocol[id], edocol["email1"],
                   edocol[email1]))  # add the email address
    globals.g.add((edocol[id], edocol["email2"],
                   edocol[email2]))  # add the email address
    globals.g.add((edocol[id], edocol["email3"],
                   edocol[email3]))  # add the email address
    globals.g.add(
        (edocol[id], edocol["password"], edocol[password]))  # add the password

    #Write database
    globals.writedb()
    return id
Пример #27
0
def new(pid, name, content):
  """ pre:  id,  unique time
      post: a new page id is added to g. The user is added as owner and to the whitelist and a first
      version of the document is created. """
  #Initialisation
  did = globals.newdid()
  
  # Create initial nodes
  globals.g.add((edodoc[str(did)], edodoc['type'], Literal("document")))
  
  # Setting owner, reverse owner and 
  globals.g.add((edodoc[str(did)], edodoc['owner'], edocol[str(pid)]))              # ownership
  
  # Assign values
  globals.g.add((edodoc[str(did)], edodoc['name'], Literal(name) ))             # assign name
  globals.g.add((edodoc[str(did)], edodoc['content'], Literal(content)))             # assign empty content
  #Write database
  globals.writedb()
  return did
Пример #28
0
def new(pid, name, content):
    """ pre:  id,  unique time
      post: a new page id is added to g. The user is added as owner and to the whitelist and a first
      version of the document is created. """
    # Initialisation
    did = globals.newdid()

    # Create initial nodes
    globals.g.add((edodoc[str(did)], edodoc["type"], Literal("document")))

    # Setting owner, reverse owner and
    globals.g.add((edodoc[str(did)], edodoc["owner"], edocol[str(pid)]))  # ownership

    # Assign values
    globals.g.add((edodoc[str(did)], edodoc["name"], Literal(name)))  # assign name
    globals.g.add((edodoc[str(did)], edodoc["content"], Literal(content)))  # assign empty content
    # Write database
    globals.writedb()
    return did
Пример #29
0
def delete(did):
  """ pre: identifier van een page
      post: de page word verwijdert """
  
  ###################
  ## H4xx0rz
  ##################$
  
  # delete type
  target = globals.g.query( """
                SELECT ?v 
                WHERE { edodoc:%s edodoc:type ?v .}""" % (did, ), 
                initNs=globals.ns).serialize('python')
  print target
  globals.g.remove((edodoc[str(did)], edodoc['type'], target[0]))

  # delete type
  target = globals.g.query( """
                SELECT ?v 
                WHERE { edodoc:%s edodoc:owner ?v .}""" % (did, ), 
                initNs=globals.ns).serialize('python')   
  globals.g.remove((edodoc[str(did)], edodoc['owner'], target[0]))
  
  # delete type
  target = globals.g.query( """
                SELECT ?v 
                WHERE { edodoc:%s edodoc:name ?v .}""" % (did, ), 
                initNs=globals.ns).serialize('python')   
  globals.g.remove((edodoc[str(did)], edodoc['name'], target[0]))
  
  # delete type
  target = globals.g.query( """
                SELECT ?v 
                WHERE { edodoc:%s edodoc:content ?v .}""" % (did, ), 
                initNs=globals.ns).serialize('python')   
  globals.g.remove((edodoc[str(did)], edodoc['content'], target[0]))

    
  #Write database
  globals.writedb()
  return True
Пример #30
0
def setpropertyvalue(id, property, value):
    assert (not (value in getpropertyvalue(
        id, property))), 'already has that value for that property'

    if property == 'email':
        email1 = ''
        email2 = ''
        email3 = ''
        phase = 1

        for char in value:
            if phase == 3:
                if char == '.':
                    assert False, 'email address cannot contain more than 1 dot.'
                else:
                    email3 = email3 + char
            if phase == 2:
                if char == '.':
                    phase = 3
                else:
                    email2 = email2 + char
            if phase == 1:
                if char == '@':
                    phase = 2
                else:
                    email1 = email1 + char

        assert ((not (property == email1)) and (not (property == email2))
                and (not (property
                          == email3))), 'cannot set email# properties directly'

        globals.g.set((edocol[id], edocol['email1'], edocol[email1]))
        globals.g.set((edocol[id], edocol['email2'], edocol[email2]))
        globals.g.set((edocol[id], edocol['email3'], edocol[email3]))

    else:
        globals.g.set((edocol[id], edocol[property], edocol[value]))

    #Write database
    globals.writedb()
    return True
Пример #31
0
def setpropertyvalue(id, property, value):
  assert (not (value in getpropertyvalue(id, property))), 'already has that value for that property'

  
  if property == 'email':
    email1 = ''
    email2 = ''
    email3 = ''
    phase = 1

    for char in value:
      if phase == 3:
        if char == '.':
          assert False, 'email address cannot contain more than 1 dot.'
        else:
          email3 = email3 + char  
      if phase == 2:
        if char == '.':
          phase = 3
        else:
          email2 = email2 + char  
      if phase == 1:
        if char == '@':
          phase = 2
        else:
          email1 = email1 + char 
          
    assert ((not (property == email1)) and (not (property == email2)) and (not (property == email3))), 'cannot set email# properties directly'
          
    globals.g.set( (edocol[id], edocol['email1'], edocol[email1]) )   
    globals.g.set( (edocol[id], edocol['email2'], edocol[email2]) )   
    globals.g.set( (edocol[id], edocol['email3'], edocol[email3]) )   
    
  else:
    globals.g.set( (edocol[id], edocol[property], edocol[value]) )    
  
  #Write database
  globals.writedb()
  return True 
Пример #32
0
def new(name, password, email):
  # add new user
  id = newuserid()
  
  email1 = ''
  email2 = ''
  email3 = ''
  phase = 1
  
  for char in email:
    if phase == 3:
      if char == '.':
        assert False, 'email address cannot contain more than 1 dot.'
      else:
        email3 = email3 + char  
    if phase == 2:
      if char == '.':
        phase = 3
      else:
        email2 = email2 + char  
    if phase == 1:
      if char == '@':
        phase = 2
      else:
        email1 = email1 + char

  assert (fromemail(email) == []), 'email address already in use'


  globals.g.add( (edocol[id], edocol["type"], edocol["person"])    )   # add the person
  globals.g.add( (edocol[id], edocol["name"], edocol[name])         ) # add the name
  globals.g.add( (edocol[id], edocol["email1"], edocol[email1])       )	# add the email address 
  globals.g.add( (edocol[id], edocol["email2"], edocol[email2])       )	# add the email address  
  globals.g.add( (edocol[id], edocol["email3"], edocol[email3])       )	# add the email address    
  globals.g.add( (edocol[id], edocol["password"], edocol[password]) ) # add the password

  #Write database
  globals.writedb()
  return id
Пример #33
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))
Пример #34
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))
Пример #35
0
 def exitdb(self):
   globals.writedb()