Пример #1
0
def insertIntoGraph(queue):
    """Insert queue content into graph"""
    seqAuthor = 1
    
    #authorFilter = loadAuthor()
    #authorFilter = loadAuthorFilter()
    authorFilter = [node.name for node in graph.find("Author")]
    
    while True:
        pubAttrs = queue.get()
        if pubAttrs is None:
            break
        include = False
        if pubAttrs.get('author') is None:
            continue
        for author in pubAttrs.get('author'):
            author = author.strip()
            if [x for x in authorFilter if compareNames(removeAccents(x['name']), removeAccents(author))]:
                include = True
        
        if not include:
            continue
        newpub = graph.find_one("Publication", "title", pubAttrs.get("title"))
        if newpub is None:
            logging.info("Creating new publication" + pubAttrs.get("title", ""))
            newpub = Node()
            for att in pubAttrs.keys():
                newpub[att] = pubAttrs.get(att, -1)

            newpub.add_label('Publication')
            graph.create(newpub)
        else:
            continue

        for aName in list(pubAttrs['author']):
            author = None
            for authorNode in graph.find("Author"):
                if compareNames(removeAccents(authorNode['name']), removeAccents(aName)):
                    author = authorNode
                    break

            if author is None:
                author = Node("Author", name=aName)
                graph.create(author)
                logging.info("New author created: %s" % aName)
            relAuthoring = Relationship(author, "AUTHORING", newpub)
            logging.info("!!! Creating relationship: " + newpub.get('title'))
            graph.create(relAuthoring)
            
    print("All insertions done")
Пример #2
0
def create_user(handle, **kwargs):
    """Attempts to create a user based on a handle and other keyword
    arguments. If the handle is already taken we print a message and return.

    returns: None

    Note: in this implementation twitter handles ARE case-sensitive
    """

    if find_one("User", "handle", handle) is not None:
        print("Handle", handle, "already taken!")
        return

    user = Node("User", handle=handle, **kwargs)
    GRAPH.create(user)

    print("Created User:", user.get('handle'))