def get_drt(): if request.method != 'POST': return [] data = json.loads(request.data) text = data['text'] discourse = Discourse(text) writer = DRTTripletsWriter() triplets = discourse.apply(writer) return jsonify(triplets)
def _substitute_text_in_match_statement_with_graph(text, substitution_triggers): drs_cleaner = DrsNERCleaner(substitution_triggers) p = re.compile('MATCH.*\"(.*)\"') lst = p.findall(text) if not lst: p = re.compile('MATCH.*\'(.*)\'') lst = p.findall(text) for item in lst: try: drs = Discourse(item).connected_components[0] except IndexError: _logger.warning('Cannot use Discourse on %s' % item[:200]) drs = Drs.create_from_natural_language(item) drs = drs.apply(drs_cleaner) text = text.replace('"' + item + '"', str(drs)) return text