Beispiel #1
0
// Open opens a new BOW database for reading. In particular, all entries
// in the database will be loaded into memory.
func Open(fpath string) (*DB, error) {
	var err error

	db := &DB{
		Name:        path.Base(fpath),
		readAllLock: new(sync.Mutex),
	}

	dbf, err := os.Open(fpath)
	if err != nil {
		return nil, err
	}
	tr := tar.NewReader(dbf)

	if _, err := tr.Next(); err != nil { // the dir header, skip it
		return nil, err
	}
	if _, err := tr.Next(); err != nil { // the flib header
		return nil, err
	}

	db.Lib, err = fragbag.Open(tr)
	if err != nil {
		return nil, err
	}

	if _, err := tr.Next(); err != nil { // the bow db header
		return nil, err
	}
	db.fileBuf = bufio.NewReaderSize(tr, 1<<20)
	return db, nil
}
Beispiel #2
0
func init() {
	var err error
	var flib *os.File

	flib_path := os.Getenv("FRAGLIB_PATH")
	if len(flib_path) == 0 {
		log.Fatal("Environment variable FRAGLIB_PATH must be set.")
	}

	flib, err = os.Open(fmt.Sprintf("%s/structure/400-11.json", flib_path))
	if err != nil {
		log.Fatal(err)
	}

	library, err = fragbag.Open(flib)
	if err != nil {
		log.Fatal(err)
	}

	oldstyle = []string{
		"aaaaa",
		"126#258#386#",
		"abcdefYZ#52#53#54#abcdef",
	}
	newstyle = []Bow{
		newBowMap(library.Size(), map[int]float32{0: 5}),
		newBowMap(library.Size(), map[int]float32{
			126: 1, 258: 1, 386: 1,
		}),
		newBowMap(library.Size(), map[int]float32{
			0: 2, 1: 2, 2: 2, 3: 2, 4: 2, 5: 2,
			50: 1, 51: 1, 52: 1, 53: 1, 54: 1,
		}),
	}
}
Beispiel #3
0
func Library(fpath string) fragbag.Library {
	libPath := os.Getenv("FRAGLIB_PATH")
	if !Exists(fpath) && len(libPath) > 0 {
		fpath = path.Join(libPath, fpath)
		if !strings.HasSuffix(fpath, ".json") {
			fpath += ".json"
		}
	}
	lib, err := fragbag.Open(OpenFile(fpath))
	Assert(err, "Could not open fragment library '%s'", fpath)
	return lib
}