MaltParser.NET


Parse sentences with MaltParser

This example shows how to parse a sentence with MaltParser by first initialize a parser model.

To run this example requires that you have created swemalt-1.7.2i.mco.

You can download model from pre-trainted models page.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
#r "maltparser-1.8.1.dll"
#r "IKVM.OpenJDK.Core.dll"

open java.io
open org.maltparser.concurrent

// Loading the Swedish model swemalt-1.7.2
let swemaltMiniModelURL = File(__SOURCE_DIRECTORY__ + "/../../paket-files/www.maltparser.org/swemalt-1.7.2.mco").toURI().toURL()
let model = ConcurrentMaltParserService.initializeParserModel(swemaltMiniModelURL)

// Creates an array of tokens, which contains the Swedish sentence
// 'Samtidigt får du högsta sparränta plus en skattefri sparpremie.'
// in the CoNLL data format.
let tokens =
  [|"1\tSamtidigt\t_\tAB\tAB\t_"
    "2\tfår\t_\tVB\tVB\tPRS|AKT"
    "3\tdu\t_\tPN\tPN\tUTR|SIN|DEF|SUB"
    "4\thögsta\t_\tJJ\tJJ\tSUV|UTR/NEU|SIN/PLU|DEF|NOM"
    "5\tsparränta\t_\tNN\tNN\tUTR|SIN|IND|NOM"
    "6\tplus\t_\tAB\tAB\t_"
    "7\ten\t_\tDT\tDT\tUTR|SIN|IND"
    "8\tskattefri\t_\tJJ\tJJ\tPOS|UTR|SIN|IND|NOM"
    "9\tsparpremie\t_\tNN\tNN\tUTR|SIN|IND|NOM"
    "10\t.\t_\tMAD\tMAD\t_"|]

let outputGraph = model.parse(tokens)
printfn "%A" outputGraph

1	Samtidigt	_	AB	AB	_	2	TA	_	_
2	får	_	VB	VB	PRS|AKT	0	ROOT	_	_
3	du	_	PN	PN	UTR|SIN|DEF|SUB	2	SS	_	_
4	högsta	_	JJ	JJ	SUV|UTR/NEU|SIN/PLU|DEF|NOM	5	AT	_	_
5	sparränta	_	NN	NN	UTR|SIN|IND|NOM	2	OO	_	_
6	plus	_	AB	AB	_	5	ET	_	_
7	en	_	DT	DT	UTR|SIN|IND	9	DT	_	_
8	skattefri	_	JJ	JJ	POS|UTR|SIN|IND|NOM	9	AT	_	_
9	sparpremie	_	NN	NN	UTR|SIN|IND|NOM	6	PA	_	_
10	.	_	MAD	MAD	_	2	IP	_	_
namespace java
namespace java.io
namespace org
namespace org.maltparser
namespace org.maltparser.concurrent
val swemaltMiniModelURL : java.net.URL

Full name: MaltParser.swemaltMiniModelURL
Multiple items
type File =
  new : pathname:string -> File + 3 overloads
  member canExecute : unit -> bool
  member canRead : unit -> bool
  member canWrite : unit -> bool
  member compareTo : pathname:File -> int + 1 overload
  member createNewFile : unit -> bool
  member delete : unit -> bool
  member deleteOnExit : unit -> unit
  member equals : obj:obj -> bool
  member exists : unit -> bool
  ...

Full name: java.io.File

--------------------
File(pathname: string) : unit
File(uri: java.net.URI) : unit
File(parent: string, child: string) : unit
File(parent: File, child: string) : unit
val model : ConcurrentMaltParserModel

Full name: MaltParser.model
Multiple items
type ConcurrentMaltParserService =
  new : unit -> ConcurrentMaltParserService
  static member initializeParserModel : mcoURL:URL -> ConcurrentMaltParserModel + 1 overload

Full name: org.maltparser.concurrent.ConcurrentMaltParserService

--------------------
ConcurrentMaltParserService() : unit
ConcurrentMaltParserService.initializeParserModel(mcoFile: File) : ConcurrentMaltParserModel
ConcurrentMaltParserService.initializeParserModel(mcoURL: java.net.URL) : ConcurrentMaltParserModel
val tokens : string []

Full name: MaltParser.tokens
val outputGraph : graph.ConcurrentDependencyGraph

Full name: MaltParser.outputGraph
ConcurrentMaltParserModel.parse(tokens: string []) : graph.ConcurrentDependencyGraph
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Fork me on GitHub