Пример #1
0
func TestParseTreeRemapById(t *testing.T) {
	m := bimap.New()
	for _, c := range labelIdRemapCases {
		tree := FromString(c)
		tree.RemapByLabel(m)
		tree.Label = nil
		tree.Map = nil
		tree.RemapById(m)
		checkLabelId(tree.Label, tree.Id, m, t)
		tree.Label = nil
		tree.RemapById(nil)
		checkLabelId(tree.Label, tree.Id, m, t)
	}
}
Пример #2
0
func TestParseTreeRemapByLabel(t *testing.T) {
	m := bimap.New()
	for _, c := range labelIdRemapCases {
		tree := FromString(c)
		if tree.Topology.NumNodes() != len(tree.Label) {
			t.Errorf("Topology has %d nodes; Lable has %d labels", tree.Topology.NumNodes(), len(tree.Label))
		}
		tree.RemapByLabel(m)
		checkLabelId(tree.Label, tree.Id, m, t)
		tree.Id = nil
		tree.RemapByLabel(nil)
		checkLabelId(tree.Label, tree.Id, m, t)
	}
}
Пример #3
0
func TestParseTreeFill(t *testing.T) {
	flags := []int{0, FILL_LABEL_ID, FILL_SPAN, FILL_HEAD, FILL_HEAD_LEAF, FILL_YIELD, FILL_POS, FILL_UP_LINK, FILL_EVERYTHING}
	finder := &heads.TableHeadFinder{nil, heads.HEAD_FINAL}
	m := bimap.New()

	tree := FromString("((A (B C) (D E)))")
	tree.RemapByLabel(m)
	tree.FillSpan()
	tree.FillHead(finder)
	tree.FillHeadLeaf()
	tree.FillYield()
	tree.FillPOS()
	tree.Topology.FillUpLink()

	for _, flag := range flags {
		tree1 := FromString("((A (B C) (D E)))")
		tree1.Fill(flag, m, finder)
		if (flag == FILL_EVERYTHING || flag&FILL_LABEL_ID != 0) && !reflect.DeepEqual(tree.Id, tree1.Id) {
			t.Errorf("expected %v; got %v when FILL_LABEL_ID", tree.Id, tree1.Id)
		}
		if (flag == FILL_EVERYTHING || flag&FILL_SPAN != 0) && !reflect.DeepEqual(tree.Span, tree1.Span) {
			t.Errorf("expected %v; got %v when FILL_SPAN", tree.Span, tree1.Span)
		}
		if (flag == FILL_EVERYTHING || flag&FILL_HEAD != 0) && !reflect.DeepEqual(tree.Head, tree1.Head) {
			t.Errorf("expected %v; got %v when FILL_HEAD", tree.Head, tree1.Head)
		}
		if (flag == FILL_EVERYTHING || flag&FILL_HEAD_LEAF != 0) && !reflect.DeepEqual(tree.HeadLeaf, tree1.HeadLeaf) {
			t.Errorf("expected %v; got %v when FILL_HEAD_LEAF", tree.HeadLeaf, tree1.HeadLeaf)
		}
		if (flag == FILL_EVERYTHING || flag&FILL_YIELD != 0) && !reflect.DeepEqual(tree.Yield, tree1.Yield) {
			t.Errorf("expected %v; got %v when FILL_YIELD", tree.Yield, tree1.Yield)
		}
		if (flag == FILL_EVERYTHING || flag&FILL_POS != 0) && !reflect.DeepEqual(tree.POS, tree1.POS) {
			t.Errorf("expected %v; got %v when FILL_POS", tree.POS, tree1.POS)
		}
		if (flag == FILL_EVERYTHING || flag&FILL_UP_LINK != 0) && !reflect.DeepEqual(tree.Topology.UpLink, tree1.Topology.UpLink) {
			t.Errorf("expected %v; got %v when FILL_UP_LINK", tree.Topology.UpLink, tree1.Topology.UpLink)
		}
	}

	label := tree.Label
	tree.Label = nil
	tree.Fill(FILL_LABEL_ID, nil, nil)
	if !reflect.DeepEqual(label, tree.Label) {
		t.Errorf("expected %v; got %v after filling Label from Id", label, tree.Label)
	}
}
Пример #4
0
func TestParseTreeTopsort(t *testing.T) {
	m := bimap.New()
	finder := &heads.TableHeadFinder{nil, heads.HEAD_FINAL}
	for _, c := range treeTopsortCases {
		input, output := c.input, c.output
		input.Topology.Disconnect(c.remove)
		input.RemapByLabel(m)
		input.FillSpan()
		input.FillHead(finder)
		input.FillHeadLeaf()
		input.Topsort()

		output.RemapByLabel(m)
		output.FillSpan()
		output.FillHead(finder)
		output.FillHeadLeaf()

		if !equiv(input, output) {
			t.Errorf("expected %q; got %v", output, input)
		}
	}
}