Esempio n. 1
0
File: main.go Progetto: postfix/dpar
func main() {
	flag.Parse()

	if flag.NArg() != 2 {
		flag.Usage()
		os.Exit(1)
	}

	configFile, err := os.Open(flag.Arg(0))
	common.ExitIfError(err)
	defer configFile.Close()
	config, err := common.ParseConfig(configFile)
	common.ExitIfError(err)

	log.Printf("Transition system: %s", config.Parser.System)
	if config.Parser.HashKernelSize > 0 {
		log.Printf("Hash kernel size: %d", config.Parser.HashKernelSize)
	}

	generator, err := common.ReadFeatures(config.Parser.Features)
	common.ExitIfError(err)

	transitionSystem, ok := common.TransitionSystems[config.Parser.System]
	if !ok {
		log.Fatalf("Unknown transition system: %s", config.Parser.System)
	}

	oracleConstructor, ok := common.Oracles[config.Parser.System]
	if !ok {
		log.Fatalf("Unknown transition system: %s", config.Parser.System)
	}

	log.Println("Creating training instances...")
	var collector svm.GoLinearCollector
	if config.Parser.HashKernelSize == 0 {
		collector = featureParsing(transitionSystem, generator, oracleConstructor)
	} else {
		collector = hashKernelParsing(transitionSystem, generator, oracleConstructor,
			config.Parser.HashKernelSize)
	}

	if *libsvmOutput != "" {
		writeLibSVMOutput(collector.Problem())
	}

	if config.Parser.Model != "" {
		model := trainModel(config.LibLinear, collector.Problem())
		err := model.Save(config.Parser.Model)
		common.ExitIfError(err)
	}

	writeTransitions(transitionSystem, collector, config.Parser.Transitions)

	log.Println("Done!")
}
Esempio n. 2
0
File: main.go Progetto: postfix/dpar
func main() {
	flag.Parse()

	if flag.NArg() != 2 {
		flag.Usage()
		os.Exit(1)
	}

	configFile, err := os.Open(flag.Arg(0))
	common.ExitIfError(err)
	defer configFile.Close()
	config, err := common.ParseConfig(configFile)
	common.ExitIfError(err)

	generator, err := common.ReadFeatures(config.Parser.Features)
	common.ExitIfError(err)

	transitionSystem, ok := common.TransitionSystems[config.Parser.System]
	if !ok {
		log.Fatalf("Unknown transition system: %s", config.Parser.System)
	}

	labelNumberer, err := common.ReadTransitions(config.Parser.Transitions, transitionSystem)
	common.ExitIfError(err)

	model, err := golinear.LoadModel(config.Parser.Model)
	common.ExitIfError(err)

	if config.Parser.HashKernelSize == 0 {
		log.Fatal("Currently only models using a hash kernel are supported")
	} else {
		hashKernelParsing(transitionSystem, generator, model, labelNumberer,
			config.Parser.HashKernelSize)
	}

}