예제 #1
0
파일: main.go 프로젝트: postfix/dpar
func run(parser system.Parser) {
	inputFile, err := os.Open(flag.Arg(1))
	defer inputFile.Close()
	if err != nil {
		panic("Cannot open training data")
	}

	inputReader := conllx.NewReader(bufio.NewReader(inputFile))
	writer := conllx.NewWriter(os.Stdout)

	for {
		s, err := inputReader.ReadSentence()
		if err != nil {
			break
		}

		deps, err := parser.Parse(s)
		common.ExitIfError(err)

		// Clear to ensure that no dependencies in the input leak
		// (if they were present).
		for idx := range s {
			s[idx].SetHead(0)
			s[idx].SetHeadRel("NULL")
		}

		for dep := range deps {
			s[dep.Dependent-1].SetHead(dep.Head)
			s[dep.Dependent-1].SetHeadRel(dep.Relation)
		}

		writer.WriteSentence(s)
	}
}
예제 #2
0
파일: main.go 프로젝트: danieldk/dparnn
func evaluate(parser system.Parser) {
	testFile, err := os.Open(flag.Arg(1))
	defer testFile.Close()
	if err != nil {
		panic("Cannot open evaluation data")
	}

	testReader := conllx.NewReader(bufio.NewReader(testFile))

	total := 0
	found := 0
	count := 0

	for {
		s, err := testReader.ReadSentence()
		if err != nil {
			break
		}

		goldDeps, err := system.SentenceToDependencies(s)
		if err != nil {
			log.Fatal(err)
		}

		deps, err := parser.Parse(s)
		if err != nil {
			log.Fatal(err)
		}

		total += len(goldDeps)
		found += foundAttachments(goldDeps, deps)
		count++

		if count%100 == 0 {
			printAccuracy(found, total)
		}
	}

	printAccuracy(found, total)
}