Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6852647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:25:05+00:00 2026-05-27T01:25:05+00:00

I am trying to parse the result output from a natural language parser (Stanford

  • 0

I am trying to parse the result output from a natural language parser (Stanford parser).
Some of the results are as below:

dep(Company-1, rent-5')
conj_or(rent-5, share-10)
amod(information-12, personal-11)
prep_about(rent-5, you-14)
amod(companies-20, non-affiliated-19)
aux(provide-23, to-22)
xcomp(you-14, provide-23)
dobj(provide-23, products-24)
aux(requested-29, 've-28)

The result am trying to get are:

['dep', 'Company', 'rent']
['conj_or', 'rent', 'share']
['amod', 'information', 'personal']
...
['amod', 'companies', 'non-affiliated']
...
['aux', 'requested', "'ve"]

First I tried to directly get these elements out, but failed.
Then I realized regex should be the right way forward.

However, I am totally unfamiliar with regex. With some exploration, I got:

m = re.search('(?<=())\w+', line)
m2 =re.search('(?<=-)\d', line)

and stuck.

The first one can correctly get the first elements, e.g. 'dep', 'amod', 'conj_or', but I actually have not totally figured out why it is working…

Second line is trying to get the second elements, e.g. 'Company', 'rent', 'information', but I can only get the number after the word. I cannot figure out how to lookbefore rather than lookbehind…

BTW, I also cannot figure out how to deal with exceptions such as 'non-affiliated' and "'ve".

Could anyone give some hints or help. Highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:25:06+00:00Added an answer on May 27, 2026 at 1:25 am

    It is difficult to give an optimal answer without knowing the full range of possible outputs, however, here’s a possible solution:

    >>> [re.findall(r'[A-Za-z_\'-]+[^-\d\(\)\']', line) for line in s.split('\n')]
    [['dep', 'Company', 'rent'], 
     ['conj_or', 'rent', 'share'], 
     ['amod', 'information', 'personal'], 
     ['prep_about', 'rent', 'you'], 
     ['amod', 'companies', 'non-affiliated'], 
     ['aux', 'provide', 'to'], 
     ['xcomp', 'you', 'provide'], 
     ['dobj', 'provide', 'products'], 
     ['aux', 'requested', "'ve"]]
    

    It works by finding all the groups of contiguous letters ([A-Za-z] represent the interval between capital A and Z and small a and z) or the characters “_” and “‘” in the same line.

    Furthermore it enforce the rule that your matched string must not have in the last position a given list of characters ([^...] is the syntax to say “must not contain any of the characters (replace “…” with the list of characters)).

    The character \ escapes those characters like “(” or “)” that would otherwise be parsed by the regex engine as instructions.

    Finally, s is the example string you gave in the question…

    HTH!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse an xml file output from googletest to display the results
I'm trying to parse some JSON data from the Google AJAX Search API. I
Trying to parse an HTML document and extract some elements (any links to text
Trying to parse some XML but apparently this is too much for a lazy
I'm trying to parse the following HTML from the following URL: http://md5.rednoize.com/?q=fbade9e36a3f36d3d676c1b808451dd7 The code:
I'm trying to parse a string I get from a hashtag, and so far
I am trying to get the following output format from a CI query and
I am trying to figure out the best way to parse a search results
I am trying to parse JSON file generated from ColdFusion server in SerializeJSON format.
Trying to parse Maplines for an airport. Each airport can have X number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.