bdmarius / python-knowledge-graph

A Python implementation of a basic Knowledge Graph
104 stars 29 forks source link

Subject/object construction never updated #3

Open amansani opened 3 years ago

amansani commented 3 years ago

Hello, Thanks for writing this code. It gives us basic idea to start working with KG.

In knowledgegraph.py file, once we enter the processSubjectObjectPairs(tokens) function, you are assigning empty string to subjectConstruction and objectConstruction variables. After that there is no update of value to that variable, to update we need to pass "if subjectConstruction" or "if objectConstruction" conditions. But the values to those variables are empty strings, so we can never pass that condition to update those values. Can you please fix it? Thanks.

if isConstructionCandidate(token): if subjectConstruction: subjectConstruction = appendChunk(subjectConstruction, token.text) if objectConstruction: objectConstruction = appendChunk(objectConstruction, token.text)

amansani commented 3 years ago

May be something like this:

``def processSubjectObjectPairs(tokens): subject = '' object = '' relation = ''

subjectConstruction = ''

**subjectObjectConstruction** = ''
for token in tokens:
    #printToken(token)
    if "punct" in token.dep_:
        continue
    if isRelationCandidate(token):
        relation = appendChunk(relation, token.lemma_)
    **if isConstructionCandidate(token):            
            subjectObjectConstruction = appendChunk(subjectObjectConstruction, token.text)**            
    if "subj" in token.dep_:
        subject = appendChunk(subject, token.text)
        subject = appendChunk(**subjectObjectConstruction**, subject)
        **subjectObjectConstruction** = ''
    if "obj" in token.dep_:
        object = appendChunk(object, token.text)
        object = appendChunk(**subjectObjectConstruction**, object)
        **subjectObjectConstruction** = ''