- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试为足球比赛设计一个解析器。我在这里非常宽松地使用术语“自然语言”,所以请耐心等待,因为我对这个领域知之甚少。
以下是我正在使用的一些示例(格式:TIME|DOWN&DIST|OFF_TEAM|DESCRIPTION):
04:39|4th and 20@NYJ46|Dal|Mat McBriar punts for 32 yards to NYJ14. Jeremy Kerley - no return. FUMBLE, recovered by NYJ.|
04:31|1st and 10@NYJ16|NYJ|Shonn Greene rush up the middle for 5 yards to the NYJ21. Tackled by Keith Brooking.|
03:53|2nd and 5@NYJ21|NYJ|Mark Sanchez rush to the right for 3 yards to the NYJ24. Tackled by Anthony Spencer. FUMBLE, recovered by NYJ (Matthew Mulligan).|
03:20|1st and 10@NYJ33|NYJ|Shonn Greene rush to the left for 4 yards to the NYJ37. Tackled by Jason Hatcher.|
02:43|2nd and 6@NYJ37|NYJ|Mark Sanchez pass to the left to Shonn Greene for 7 yards to the NYJ44. Tackled by Mike Jenkins.|
02:02|1st and 10@NYJ44|NYJ|Shonn Greene rush to the right for 1 yard to the NYJ45. Tackled by Anthony Spencer.|
01:23|2nd and 9@NYJ45|NYJ|Mark Sanchez pass to the left to LaDainian Tomlinson for 5 yards to the 50. Tackled by Sean Lee.|
到目前为止,我已经编写了一个愚蠢的解析器来处理所有简单的东西(playID、季度、时间、下降和距离、进攻球队)以及一些脚本来获取这些数据并将其清理成上面看到的格式.单行变成“播放”对象以存储到数据库中。
这里最困难的部分(至少对我而言)是解析剧本的描述。这是我想从该字符串中提取的一些信息:
示例字符串:
"Mark Sanchez pass to the left to Shonn Greene for 7 yards to the NYJ44. Tackled by Mike Jenkins."
结果:
turnover = False
interception = False
fumble = False
to_on_downs = False
passing = True
rushing = False
direction = 'left'
loss = False
penalty = False
scored = False
TD = False
PA = False
FG = False
TPC = False
SFTY = False
punt = False
kickoff = False
ret_yardage = 0
yardage_diff = 7
playmakers = ['Mark Sanchez', 'Shonn Greene', 'Mike Jenkins']
我的初始解析器逻辑是这样的:
# pass, rush or kick
# gain or loss of yards
# scoring play
# Who scored? off or def?
# TD, PA, FG, TPC, SFTY?
# first down gained
# punt?
# kick?
# return yards?
# penalty?
# def or off?
# turnover?
# INT, fumble, to on downs?
# off play makers
# def play makers
描述可能会变得非常复杂(多次失误和恢复并受到惩罚等),我想知道我是否可以利用那里的一些 NLP 模块。我可能会花几天时间研究像解析器这样的哑/静态状态机,但如果有人对如何使用 NLP 技术处理它有建议,我想听听他们的意见。
最佳答案
我认为 pyparsing 在这里非常有用。
您的输入文本看起来非常规则(不像真正的自然语言),而 pyparsing 在这方面做得很好。你应该看看它。
例如解析下面的句子:
Mat McBriar punts for 32 yards to NYJ14.
Mark Sanchez rush to the right for 3 yards to the NYJ24.
你可以用类似的东西定义一个解析语句(在文档中寻找准确的语法):
name = Group(Word(alphas) + Word(alphas)).setResultsName('name')
action = Or(Exact("punts"),Exact("rush")).setResultsName('action') + Optional(Exact("to the")) + Or(Exact("left"), Exact("right")) )
distance = Word(number).setResultsName("distance") + Exact("yards")
pattern = name + action + Exact("for") + distance + Or(Exact("to"), Exact("to the")) + Word()
并且 pyparsing 会使用这种模式来破坏字符串。它还将返回一个字典,其中包含从句子中提取的项目名称、 Action 和距离。
关于python - 用于解析体育比赛数据的自然语言解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8198923/
我有一套使用两种语言的文档:英语和德语。关于这些文档没有可用的元信息,程序只能查看其内容。基于此,程序必须决定用哪种语言编写文档。 是否有可以在几个小时内实现的针对该问题的“标准”算法?或者,一个免费
背景 我有一个日志系统,可以将记录输出到 std::ostream .每条记录都用一个计数器进行注释,该计数器随着每个输出而增加 1,如下所示: ===== Batch # 5 ===== T
用户可能希望根据需要分隔数字。 从字符串中提取所有(自然)数字的最有效(或简单的标准函数)是什么? 最佳答案 您可以使用正则表达式。我从 Sun's regex matcher tutorial 修改
我认为如果表有代理键而没有(自然)替代键是没有意义的(请记住,代理键的属性之一是它在数据库之外没有意义环境)。 例如假设我有下表: 假设 employee_id 是代理主键,表中没有(自然)备用键。
我想将屏幕方向锁定为其默认方向。我在实现这一点时遇到问题。最初我将屏幕锁定为 list 中的肖像。它适用于纵向默认设备。但是许多平板电脑默认为横向,因此在这些设备中锁定纵向是不合适的,我想检测此默认方
我已将笔记本电脑上的触摸板滚动设置为倒置(自然)。它适用于任何地方(pdf、浏览器等),但在 vscode 中,它坚持正常滚动。通过 vscode 的设置文件没有显示适当的条目。 系统:Ubuntu
在我发现的许多在上限集合上使用可尾游标的示例中,代码包括: hint( { $natural: 1 } ) (例如 here ),包括官方文档 ( here ),以“确保我们不使用任何索引”,并且结果
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: T
一些上下文:Node.js、Bot、natural module . 我想构建一个机器人,并且我正在使用自然模块来解析用户输入并对其进行总体分类。 var classifier = new natur
我是一名优秀的程序员,十分优秀!