<commit_before>package transition

import (
	"fmt"
	. "yap/alg/transition"
	. "yap/nlp/types"
	"yap/util"
	// "log"
)

type ArcStandard struct {
	oracle             Oracle
	Relations          *util.EnumSet
	Transitions        *util.EnumSet
	SHIFT, LEFT, RIGHT int
}

// Verify that ArcStandard is a TransitionSystem
var _ TransitionSystem = &ArcStandard{}

func (a *ArcStandard) Transition(from Configuration, rawTransition Transition) Configuration {
	conf, ok := from.Copy().(*SimpleConfiguration)
	if !ok {
		panic("Got wrong configuration type")
	}
	transition := rawTransition.Value()
	// Transition System:
	// LA-r	(S|wi,	wj|B,	A) => (S   ,	wj|B,	A+{(wj,r,wi)})	if: i != 0
	// RA-r	(S|wi, 	wj|B,	A) => (S   ,	wi|B, 	A+{(wi,r,wj)})
	// SH	(S   ,	wi|B, 	A) => (S|wi,	   B,	A)
	// switch transition[:2] {
	switch {
	// case "LA":
	case transition >= a.LEFT && transition < a.RIGHT:
		wi, wiExists := conf.Stack().Pop()
		// if wi == 0 {
		// 	panic("Attempted to LA the root")
		// }
		wj, wjExists := conf.Queue().Peek()
		if !(wiExists && wjExists) {
			panic(fmt.Sprintf("Can't LA, Stack and/or Queue are/is empty: %v", conf))
		}
		// relation := DepRel(transition[3:])
		relation := int(transition - a.LEFT)
		relationValue := a.Relations.ValueOf(relation).(DepRel)
		newArc := &BasicDepArc{wj, relation, wi, relationValue}

		// conf.Arcs().Add(newArc)
		conf.AddArc(newArc)
		conf.Assign(uint16(conf.Nodes[newArc.Modifier].ID()))
	// case "RA":
	case transition >= a.RIGHT:
		wi, wiExists := conf.Stack().Pop()
		wj, wjExists := conf.Queue().Pop()
		if !(wiExists && wjExists) {
			panic("Can't RA, Stack and/or Queue are/is empty")
		}
		// rel := DepRel(transition[3:])
		rel := int(transition - a.RIGHT)
		relValue := a.Relations.ValueOf(rel).(DepRel)
		newArc := &BasicDepArc{wi, rel, wj, relValue}
		conf.Queue().Push(wi)
		conf.AddArc(newArc)
		conf.Assign(uint16(conf.Nodes[newArc.Modifier].ID()))
		// conf.Arcs().Add(newArc)
	case transition == a.SHIFT:
		wi, wiExists := conf.Queue().Pop()
		if !wiExists {
			panic("Can't shift, queue is empty")
		}
		conf.Assign(uint16(conf.Nodes[wi].ID()))
		conf.Stack().Push(wi)
	default:
		panic(fmt.Sprintf("Unknown transition %v SHIFT is %v", transition, a.SHIFT))
	}
	conf.SetLastTransition(rawTransition)
	return conf
}

func (a *ArcStandard) possibleTransitions(from Configuration, transitions chan int) {
	conf, ok := from.(*SimpleConfiguration)
	if !ok {
		panic("Got wrong configuration type")
	}
	_, qExists := conf.Queue().Peek()
	_, sExists := conf.Stack().Peek()
	if qExists {
		transitions <- a.SHIFT
	}
	// if sExists {
	// 	if sPeek != 0 {
	// 		for rel, _ := range a.Relations.Index {
	// 			// transitions <- Transition("LA-" + rel)
	// 			transitions <- Transition(int(a.LEFT) + rel)
	// 		}
	// 	}
	// }
	if sExists && qExists {
		for rel, _ := range a.Relations.Index {
			// transitions <- Transition("LA-" + rel)
			transitions <- a.LEFT + rel
		}
		for rel, _ := range a.Relations.Index {
			// transitions <- Transition("RA-" + rel)
			transitions <- a.RIGHT + rel
		}
	}
	close(transitions)
}

func (a *ArcStandard) GetTransitions(from Configuration) (byte, []int) {
	retval := make([]int, 0, 10)
	tType, transitions := a.YieldTransitions(from)
	for transition := range transitions {
		retval = append(retval, int(transition))
	}
	return tType, retval
}

func (a *ArcStandard) YieldTransitions(from Configuration) (byte, chan int) {
	transitions := make(chan int)
	go a.possibleTransitions(from, transitions)
	return '?', transitions
}

func (a *ArcStandard) TransitionTypes() []string {
	return []string{"LA-*", "RA-*", "SH"}
}

func (a *ArcStandard) Projective() bool {
	return true
}

func (a *ArcStandard) Labeled() bool {
	return true
}

func (a *ArcStandard) Oracle() Oracle {
	return a.oracle
}
<commit_msg>Fix transition type for arc standard<commit_after>package transition

import (
	"fmt"
	. "yap/alg/transition"
	. "yap/nlp/types"
	"yap/util"
	// "log"
)

type ArcStandard struct {
	oracle             Oracle
	Relations          *util.EnumSet
	Transitions        *util.EnumSet
	SHIFT, LEFT, RIGHT int
}

// Verify that ArcStandard is a TransitionSystem
var _ TransitionSystem = &ArcStandard{}

func (a *ArcStandard) Transition(from Configuration, rawTransition Transition) Configuration {
	conf, ok := from.Copy().(*SimpleConfiguration)
	if !ok {
		panic("Got wrong configuration type")
	}
	transition := rawTransition.Value()
	// Transition System:
	// LA-r	(S|wi,	wj|B,	A) => (S   ,	wj|B,	A+{(wj,r,wi)})	if: i != 0
	// RA-r	(S|wi, 	wj|B,	A) => (S   ,	wi|B, 	A+{(wi,r,wj)})
	// SH	(S   ,	wi|B, 	A) => (S|wi,	   B,	A)
	// switch transition[:2] {
	switch {
	// case "LA":
	case transition >= a.LEFT && transition < a.RIGHT:
		wi, wiExists := conf.Stack().Pop()
		// if wi == 0 {
		// 	panic("Attempted to LA the root")
		// }
		wj, wjExists := conf.Queue().Peek()
		if !(wiExists && wjExists) {
			panic(fmt.Sprintf("Can't LA, Stack and/or Queue are/is empty: %v", conf))
		}
		// relation := DepRel(transition[3:])
		relation := int(transition - a.LEFT)
		relationValue := a.Relations.ValueOf(relation).(DepRel)
		newArc := &BasicDepArc{wj, relation, wi, relationValue}

		// conf.Arcs().Add(newArc)
		conf.AddArc(newArc)
		conf.Assign(uint16(conf.Nodes[newArc.Modifier].ID()))
	// case "RA":
	case transition >= a.RIGHT:
		wi, wiExists := conf.Stack().Pop()
		wj, wjExists := conf.Queue().Pop()
		if !(wiExists && wjExists) {
			panic("Can't RA, Stack and/or Queue are/is empty")
		}
		// rel := DepRel(transition[3:])
		rel := int(transition - a.RIGHT)
		relValue := a.Relations.ValueOf(rel).(DepRel)
		newArc := &BasicDepArc{wi, rel, wj, relValue}
		conf.Queue().Push(wi)
		conf.AddArc(newArc)
		conf.Assign(uint16(conf.Nodes[newArc.Modifier].ID()))
		// conf.Arcs().Add(newArc)
	case transition == a.SHIFT:
		wi, wiExists := conf.Queue().Pop()
		if !wiExists {
			panic("Can't shift, queue is empty")
		}
		conf.Assign(uint16(conf.Nodes[wi].ID()))
		conf.Stack().Push(wi)
	default:
		panic(fmt.Sprintf("Unknown transition %v SHIFT is %v", transition, a.SHIFT))
	}
	conf.SetLastTransition(rawTransition)
	return conf
}

func (a *ArcStandard) possibleTransitions(from Configuration, transitions chan int) {
	conf, ok := from.(*SimpleConfiguration)
	if !ok {
		panic("Got wrong configuration type")
	}
	_, qExists := conf.Queue().Peek()
	_, sExists := conf.Stack().Peek()
	if qExists {
		transitions <- a.SHIFT
	}
	// if sExists {
	// 	if sPeek != 0 {
	// 		for rel, _ := range a.Relations.Index {
	// 			// transitions <- Transition("LA-" + rel)
	// 			transitions <- Transition(int(a.LEFT) + rel)
	// 		}
	// 	}
	// }
	if sExists && qExists {
		for rel, _ := range a.Relations.Index {
			// transitions <- Transition("LA-" + rel)
			transitions <- a.LEFT + rel
		}
		for rel, _ := range a.Relations.Index {
			// transitions <- Transition("RA-" + rel)
			transitions <- a.RIGHT + rel
		}
	}
	close(transitions)
}

func (a *ArcStandard) GetTransitions(from Configuration) (byte, []int) {
	retval := make([]int, 0, 10)
	tType, transitions := a.YieldTransitions(from)
	for transition := range transitions {
		retval = append(retval, int(transition))
	}
	return tType, retval
}

func (a *ArcStandard) YieldTransitions(from Configuration) (byte, chan int) {
	transitions := make(chan int)
	go a.possibleTransitions(from, transitions)
	return TransitionType, transitions
}

func (a *ArcStandard) TransitionTypes() []string {
	return []string{"LA-*", "RA-*", "SH"}
}

func (a *ArcStandard) Projective() bool {
	return true
}

func (a *ArcStandard) Labeled() bool {
	return true
}

func (a *ArcStandard) Oracle() Oracle {
	return a.oracle
}

{'fraction_non_alphanumeric': 0.17435158501440923, 'fraction_numerical': 0.0039297877914592615, 'mean_word_length': 3.5017688679245285, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5892689', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2775, 'n_words': 654}