Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to limit subject-verb-object extraction to one output per row? #188

Open
clhl opened this issue Apr 8, 2018 · 0 comments
Open

How to limit subject-verb-object extraction to one output per row? #188

clhl opened this issue Apr 8, 2018 · 0 comments

Comments

@clhl
Copy link

clhl commented Apr 8, 2018

Hi,

I am trying to extract subject-verb-object triplets from my data and then attach an ID like this:

#Make dataframe with SVO extraction
count = 0;
df2 = pd.DataFrame();
for row in df1.iterrows():
  doc = nlp(unicode(row));
  text_ext = textacy.extract.subject_verb_object_triples(doc);
  tweetID = df1['id'].tolist();
  mylist = list(text_ext)
  count = count + 1;
  if (mylist):
        df2 = df2.append(mylist, ignore_index=True)
  else:
        df2=df2.append([['0','0','0']],ignore_index=True)

#Join dataframe to attach ID
df2.columns = ['Subject', 'Verb', 'Object']
df3 = pd.concat([df2, df1], axis=1)
print df3

However for some rows more than one SVO is being extracted which is throwing the output out of line with the ID.

Is there someway to overcome this (even if it is by dropping any SVOs more than the first one per row).

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant