Python:地图字符位置到单词位置Python

发布于 2025-02-02 20:47:34 字数 911 浏览 1 评论 0原文

有没有一种方法可以自动将字符的起始位置映射到文本中的各个单词位置?

例如:

{'text': 'Metiamide an histamine H2-receptors antagonist has been used to treat a case of Zollinger-Ellison syndrome characterized by a long standing diarrhea, an important gastric hypersecretion and a moderatly elevated plasma gastrin but without digestive ulceration.',
 'char_position': '[80.0, 106.0]'}

在这里,char_position是指 Zollinger-ellison综合征

想要输出

    {'text': 'Metiamide an histamine H2-receptors antagonist has been used to treat a case of Zollinger-Ellison syndrome characterized by a long standing diarrhea, an important gastric hypersecretion and a moderatly elevated plasma gastrin but without digestive ulceration.',
     'word_position': '[13, 14]'}

Is there a way to automatically map the character start-end positions to the respective word positions in a text?

For example :

{'text': 'Metiamide an histamine H2-receptors antagonist has been used to treat a case of Zollinger-Ellison syndrome characterized by a long standing diarrhea, an important gastric hypersecretion and a moderatly elevated plasma gastrin but without digestive ulceration.',
 'char_position': '[80.0, 106.0]'}

Here, the char_position refers to Zollinger-Ellison syndrome

Wanted output :

    {'text': 'Metiamide an histamine H2-receptors antagonist has been used to treat a case of Zollinger-Ellison syndrome characterized by a long standing diarrhea, an important gastric hypersecretion and a moderatly elevated plasma gastrin but without digestive ulceration.',
     'word_position': '[13, 14]'}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文