title: How to extract numbers (along with comparison adjectives or ranges)
body: <p>I am working on two NLP projects in Python, and both have a similar task to <strong>extract numerical values and comparison operators</strong> from sentences, like the following:</p>
  
  <pre><code>"... greater than $10 ... ",
  "... weight not more than 200lbs ...",
  "... height in 5-7 feets ...",
  "... faster than 30 seconds ... "
  </code></pre>
  
  <p>I found two different approaches to solve this problem:</p>
  
  <ul>
  <li>using very complex regular expressions.</li>
  <li>using <a href="https://en.wikipedia.org/wiki/Named-entity_recognition" rel="nofollow noreferrer">Named Entity Recognition</a> (and some regexes, too).</li>
  </ul>
  
  <p>How can I parse numerical values out of such sentences? I assume this is a common task in NLP.</p>
  
  <hr>
  
  <p>The desired output would be something like:</p>
  
  <p><strong>Input:</strong></p>
  
  <blockquote>
    <p>"greater than $10"</p>
  </blockquote>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>{'value': 10, 'unit': 'dollar', 'relation': 'gt', 'position': 3}
  </code></pre>