예제 #1
0
func TestSynthesize(t *testing.T) {
	truth := `{"Obs":[[{"senior_staff":1}]],"Periods":[5]}
`
	pkg := "github.com/wangkuiyi/hmm/synthesize"
	model := "-model=" + path.Join(buildnrun.Pkg(pkg), "testdata/ground_truth_model.json")
	if out, err, e := buildnrun.Run(pkg, "-instances=1", "-cardi=1", "-length=5", "-seed=0", model); e != nil {
		t.Errorf("Failed build and run %s: %v\nOutput:\n%s", pkg, e, err)
	} else if string(out) != truth {
		t.Errorf("Expecting %s\ngot %s", truth, out)
	}
}
예제 #2
0
func TestTrain(t *testing.T) {
	trainer := "github.com/wangkuiyi/hmm/trainer"
	corpus := buildnrun.Pkg(path.Join(trainer, "testdata/corpus.json"))
	truth := `{
  "S1": [
    0,
    2
  ],
  "S1Sum": 2,
  "Σγ": [
    4,
    6
  ],
  "Σξ": [
    [
      0,
      4
    ],
    [
      6,
      0
    ]
  ],
  "Σγo": [
    [
      {
        "Hist": {
          "orange": 6
        },
        "Sum": 6
      }
    ],
    [
      {
        "Hist": {
          "apple": 6
        },
        "Sum": 6
      }
    ]
  ]
}`
	if out, err, e := buildnrun.Run(trainer, "-corpus="+corpus, "-logl=/dev/null"); e != nil {
		t.Fatalf("Failed build and run trainer: %v, %s", e, err)
	} else if out != truth {
		t.Errorf("Expecting %s, got %s", truth, out)
	}
}
예제 #3
0
func TestGenerateAndLoad(t *testing.T) {
	dir, e := ioutil.TempDir("", "converter_test")
	if e != nil {
		t.Fatalf("Cannot create temp dir: %v", e)
	}
	defer os.RemoveAll(dir)

	*flagCSV = buildnrun.Pkg(path.Join(kCSVDir, kCSVFile))
	*flagCorpus = path.Join(dir, "corpus.json")

	Run(new(PlainFeatureGenerator))

	corpus := loader.LoadJSON(α(os.Open(*flagCorpus)).(io.Reader))
	fmt.Printf("Loaded %d instances.\nThe first one:%v\nThe last one:%v\n",
		len(corpus), corpus[0], corpus[len(corpus)-1])

	if len(corpus) != 5376 {
		t.Errorf("Expecting %d instances, got %d", 5376, len(corpus))
	}
}
예제 #4
0
func TestGenerateSelectedCorpus(t *testing.T) {
	*flagCSV = buildnrun.Pkg(path.Join(kCSVDir, kCSVFile))
	*flagCorpus = "/tmp/selected_linkedin_employee_exps_corpus.json"
	Run(new(selectedMembers))
}