2011-11-20 5 views
9

Sto provando a inventare un parser per le partite di calcio. Uso il termine "linguaggio naturale" qui in modo molto approssimativo, quindi ti prego di avere pazienza con me poiché so poco o niente su questo campo.Analizzatore di lingua naturale per analizzare i dati play-by-play sportivi

Ecco alcuni esempi di ciò che sto lavorando con (Formato: TEMPO | GIÙ & DIST | OFF_TEAM | DESCRIZIONE):

04:39|4th and [email protected]|Dal|Mat McBriar punts for 32 yards to NYJ14. Jeremy Kerley - no return. FUMBLE, recovered by NYJ.| 
04:31|1st and [email protected]|NYJ|Shonn Greene rush up the middle for 5 yards to the NYJ21. Tackled by Keith Brooking.| 
03:53|2nd and [email protected]|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 [email protected]|NYJ|Shonn Greene rush to the left for 4 yards to the NYJ37. Tackled by Jason Hatcher.| 
02:43|2nd and [email protected]|NYJ|Mark Sanchez pass to the left to Shonn Greene for 7 yards to the NYJ44. Tackled by Mike Jenkins.| 
02:02|1st and [email protected]|NYJ|Shonn Greene rush to the right for 1 yard to the NYJ45. Tackled by Anthony Spencer.| 
01:23|2nd and [email protected]|NYJ|Mark Sanchez pass to the left to LaDainian Tomlinson for 5 yards to the 50. Tackled by Sean Lee.| 

A partire da ora, ho scritto un parser muto che maniglie tutte le cose facili (playID, quarter, time, down & distance, team offensivo) insieme ad alcuni script che vanno e ottengono questi dati e lo sanificano nel formato visto sopra. Una singola riga viene trasformata in un oggetto "Play" da memorizzare in un database.

La parte difficile qui (almeno per me) è l'analisi della descrizione del gioco. Ecco alcune informazioni che vorrei estrarre da quella stringa:

stringa Esempio:

"Mark Sanchez pass to the left to Shonn Greene for 7 yards to the NYJ44. Tackled by Mike Jenkins." 

Risultato:

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'] 

La logica che ho avuto per il mio parser iniziale andato qualcosa di simile :

# 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 

Le descrizioni possono ottenere abbastanza pelose (multiple armeggia & recuperi con sanzioni, ecc.) E mi chiedevo se potevo sfruttare alcuni moduli NLP là fuori. Probabilmente ho intenzione di passare qualche giorno su un computer statico muto/statico come un parser, ma se qualcuno ha suggerimenti su come affrontarlo usando le tecniche di PNL mi piacerebbe sentirli.

+9

Dato l'argomento della domanda, trovo interessante il fatto che l'evidenziatore della sintassi di SO evidenzi tutti i nomi umani ... – Jon

risposta

4

Penso che il pyparsing sarebbe molto utile qui.

Il testo di input sembra molto regolare (a differenza del linguaggio naturale reale) e il pyparsing è ottimo in questa roba. dovresti dare un'occhiata a questo

Ad esempio, per analizzare le seguenti frasi:

Mat McBriar punts for 32 yards to NYJ14. 
Mark Sanchez rush to the right for 3 yards to the NYJ24. 

definirebbe una frase parse con qualcosa come (cercare sintassi esatta in docs):

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() 

E pyparsing romperebbe le stringhe utilizzando questo modello. Restituirà anche un dizionario con gli oggetti nome, azione e distanza - estratti dalla frase.

+0

Verificherò e riferirò, grazie. – Jon

0

Immagino che il pyparsing funzionerebbe piuttosto bene, ma i sistemi basati su regole sono piuttosto fragili. Quindi, se vai oltre il calcio, potresti incontrare qualche problema.

Penso che una soluzione migliore per questo caso sarebbe una parte di speech tagger e un lessico (dizionario di lettura) di nomi di giocatori, posizioni e altra terminologia sportiva. Scaricalo nel tuo strumento di apprendimento automatico preferito, scopri le caratteristiche migliori e penso che farebbe molto bene.

NTLK è un buon punto di partenza per la PNL. Sfortunatamente, il campo non è molto sviluppato e non c'è uno strumento là fuori che sia come il bam, il problema risolto, il facile formaggio.

Problemi correlati