Example #1
0
func main() {
	flag.Parse()

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

	config := common.ReadConfigOrExit(flag.Arg(0))

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

	blasImpl, ok := blasImpls[*blas]
	if !ok {
		log.Fatalf("Unknown blas implementation: %s", *blas)
	}

	labelNumberer := common.ReadTransitionsOrExit(config.Parser.Transitions, transitionSystem)
	parseNetwork := common.ReadModelOrExit(config.Parser.Model, blasImpl)

	var morphNetwork *network.Network
	if len(config.Parser.MorphModel) != 0 {
		morphNetwork = common.ReadModelOrExit(config.Parser.MorphModel, blasImpl)
	}

	ilas := common.ReadIlasOrExit(config.Parser.Inputs)
	normalizer := common.ReadNormalizerOrExit(config.Parser.Normalisation)

	layerEmbeddings := common.MustReadAllEmbeddings(config.Embeddings)

	realizer := input.NewInputVectorRealizer(ilas, layerEmbeddings, normalizer)

	var guide system.Guide
	if morphNetwork != nil {
		log.Print("Using morphology")
		guide = network.NewMorphGuide(parseNetwork, morphNetwork, *labelNumberer, realizer)
	} else {
		guide = network.NewGuide(parseNetwork, *labelNumberer, realizer)
	}
	parser := system.NewGreedyParser(transitionSystem, guide)

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	start := time.Now()
	run(parser)
	elapsed := time.Since(start)
	log.Printf("Parsing took %s", elapsed)
}
Example #2
0
File: main.go Project: postfix/dpar
func hashKernelParsing(transitionSystem system.TransitionSystem,
	generator symbolic.FeatureGenerator, model *golinear.Model,
	labelNumberer *system.LabelNumberer, hashKernelSize uint) {
	guide := svm.NewHashingSVMGuide(model, generator, *labelNumberer, fnv.New32,
		hashKernelSize)
	parser := system.NewGreedyParser(transitionSystem, guide)

	start := time.Now()
	run(parser)
	elapsed := time.Since(start)
	log.Printf("Parsing took %s\n", elapsed)
}