Skip to content

Commit

Permalink
Merge pull request #4 from gleanerio/dv-dev_glcon
Browse files Browse the repository at this point in the history
Dv dev glcon integrate gleaner glcon and nabu
  • Loading branch information
fils authored Nov 8, 2021
2 parents 1de54e5 + 958398c commit fe23c00
Show file tree
Hide file tree
Showing 43 changed files with 1,834 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmd/nabu/nabu
**/secret/
secret/**
logs/**
/cmd/nabu/nabu
**/*.log
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
2.0.0-developement
281 changes: 145 additions & 136 deletions cmd/nabu/main.go
Original file line number Diff line number Diff line change
@@ -1,142 +1,151 @@
package main

import (
"flag"
"fmt"
"log"
"os"

"github.com/UFOKN/nabu/internal/flows"
"github.com/UFOKN/nabu/internal/objects"
"github.com/UFOKN/nabu/internal/prune"
"github.com/UFOKN/nabu/internal/semsearch"
"github.com/UFOKN/nabu/internal/tika"

// "../../internal/semsearch"

"github.com/spf13/viper"
)

var prefixVal, viperVal, modeVal string

// example source s3://noaa-nwm-retro-v2.0-pds/full_physics/2017/201708010001.CHRTOUT_DOMAIN1.comp
func init() {
log.SetFlags(log.Lshortfile)

flag.StringVar(&viperVal, "cfg", "config.json", "Configuration file")
flag.StringVar(&prefixVal, "prefix", "", "Prefix to override config file setting")
flag.StringVar(&modeVal, "mode", "", "What Nabu should do: tika, txtai, object, prefix, prune")
}
import "github.com/gleanerio/nabu/pkg/cli"

func main() {
var v1 *viper.Viper
var err error

// Set up some logging approaches
f, err := os.OpenFile("naburun.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()

log.SetOutput(f)
log.SetFlags(log.Lshortfile)
// log.SetOutput(ioutil.Discard) // turn off all logging
//wrt := io.MultiWriter(os.Stdout, f)
//log.SetOutput(wrt)

// Parse flags
flag.Parse()

if isFlagPassed("cfg") {
v1, err = readConfig(viperVal, map[string]interface{}{})
if err != nil {
panic(fmt.Errorf("error when reading config: %v", err))
}
}

mc := objects.MinioConnection(v1)

// Override prefix in config if flag set
if isFlagPassed("prefix") {
out := v1.GetStringMapString("objects")
b := out["bucket"]
p := prefixVal
// r := out["region"]
// v1.Set("objects", map[string]string{"bucket": b, "prefix": NEWPREFIX, "region": r})
v1.Set("objects", map[string]string{"bucket": b, "prefix": p})
}

// Select run mod

if !isFlagPassed("mode") {
fmt.Println("Mode must be set -mode one of: prune, tika, txtai, object, prefix")
os.Exit(0)
}

switch modeVal {

case "prefix":
fmt.Println("Load graphs from prefix to triplestore")
err = flows.ObjectAssembly(v1, mc)

if err != nil {
log.Println(err)
}

case "prune":
fmt.Println("Prune graphs in triplestore not in object store")
err = prune.Snip(v1, mc)
if err != nil {
log.Println(err)
}

case "tika":
fmt.Println("Tika extract text from objects")
err = tika.SingleBuild(v1, mc)

if err != nil {
log.Println(err)
}

case "object":
fmt.Println("Load graph object to triplestore")
spql := v1.GetStringMapString("sparql")
s, err := flows.PipeLoad(v1, mc, "bucket", "object", spql["endpoint"])
if err != nil {
log.Println(err)
}
log.Println(string(s))

case "txtai":
fmt.Println("Index descriptions to txtai")
err = semsearch.ObjectAssembly(v1, mc)
if err != nil {
log.Println(err)
}

}

cli.Execute()
}

func readConfig(filename string, defaults map[string]interface{}) (*viper.Viper, error) {
v := viper.New()
for key, value := range defaults {
v.SetDefault(key, value)
}
v.SetConfigName(filename)
v.AddConfigPath(".")
v.AutomaticEnv()
err := v.ReadInConfig()
return v, err
}

func isFlagPassed(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})
return found
}
//import (
// "flag"
// "fmt"
// "log"
// "mime"
// "os"
//
// "github.com/gleanerio/nabu/internal/flows"
// "github.com/gleanerio/nabu/internal/objects"
// "github.com/gleanerio/nabu/internal/prune"
// "github.com/gleanerio/nabu/internal/semsearch"
// "github.com/gleanerio/nabu/internal/tika"
// "github.com/gleanerio/nabu/run/cli"
// // "../../internal/semsearch"
//
// "github.com/spf13/viper"
//)
//
//var prefixVal, viperVal, modeVal string
//
//// example source s3://noaa-nwm-retro-v2.0-pds/full_physics/2017/201708010001.CHRTOUT_DOMAIN1.comp
//func init() {
// log.SetFlags(log.Lshortfile)
//
// mime.AddExtensionType(".jsonld", "application/ld+json")
//
// flag.StringVar(&viperVal, "cfg", "config.json", "Configuration file")
// flag.StringVar(&prefixVal, "prefix", "", "Prefix to override config file setting")
// flag.StringVar(&modeVal, "mode", "", "What Nabu should do: tika, txtai, object, prefix, prune")
//}
//
//func main() {
// var v1 *viper.Viper
// var err error
//
// // Set up some logging approaches
// f, err := os.OpenFile("naburun.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
// if err != nil {
// log.Fatalf("error opening file: %v", err)
// }
// defer f.Close()
//
// log.SetOutput(f)
// log.SetFlags(log.Lshortfile)
// // log.SetOutput(ioutil.Discard) // turn off all logging
// //wrt := io.MultiWriter(os.Stdout, f)
// //log.SetOutput(wrt)
//
// // Parse flags
// flag.Parse()
//
// if isFlagPassed("cfg") {
// v1, err = readConfig(viperVal, map[string]interface{}{})
// if err != nil {
// panic(fmt.Errorf("error when reading config: %v", err))
// }
// }
//
// mc := objects.MinioConnection(v1)
//
// // Override prefix in config if flag set
// if isFlagPassed("prefix") {
// out := v1.GetStringMapString("objects")
// b := out["bucket"]
// p := prefixVal
// // r := out["region"]
// // v1.Set("objects", map[string]string{"bucket": b, "prefix": NEWPREFIX, "region": r})
// v1.Set("objects", map[string]string{"bucket": b, "prefix": p})
// }
//
// // Select run mod
//
// if !isFlagPassed("mode") {
// fmt.Println("Mode must be set -mode one of: prune, tika, txtai, object, prefix")
// os.Exit(0)
// }
//
// switch modeVal {
//
// case "prefix":
// //fmt.Println("Load graphs from prefix to triplestore")
// //err = flows.ObjectAssembly(v1, mc)
// err = cli.Prefix( v1, mc)
// if err != nil {
// log.Println(err)
// }
//
// case "prune":
// fmt.Println("Prune graphs in triplestore not in object store")
// err = prune.Snip(v1, mc)
// if err != nil {
// log.Println(err)
// }
//
// case "tika":
// fmt.Println("Tika extract text from objects")
// err = tika.SingleBuild(v1, mc)
//
// if err != nil {
// log.Println(err)
// }
//
// case "object":
// fmt.Println("Load graph object to triplestore")
// spql := v1.GetStringMapString("sparql")
// s, err := flows.PipeLoad(v1, mc, "bucket", "object", spql["endpoint"])
// if err != nil {
// log.Println(err)
// }
// log.Println(string(s))
//
// case "txtai":
// fmt.Println("Index descriptions to txtai")
// err = semsearch.ObjectAssembly(v1, mc)
// if err != nil {
// log.Println(err)
// }
//
// }
//
//}
//
//func readConfig(filename string, defaults map[string]interface{}) (*viper.Viper, error) {
// v := viper.New()
// for key, value := range defaults {
// v.SetDefault(key, value)
// }
// v.SetConfigName(filename)
// v.AddConfigPath(".")
// v.AutomaticEnv()
// err := v.ReadInConfig()
// return v, err
//}
//
//func isFlagPassed(name string) bool {
// found := false
// flag.Visit(func(f *flag.Flag) {
// if f.Name == name {
// found = true
// }
// })
// return found
//}
26 changes: 26 additions & 0 deletions config/nabu
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
minio:
address: localhost
port: 9000
ssl: false
accesskey: akey
secretkey: skey
bucket: gleaner2
objects:
bucket: gleaner2
domain: us-east-1
prefix:
- milled/iris
- prov/iris
- org
prefixoff:
- summoned/aquadocs
- prov/aquadocs
- milled/opentopography
- prov/opentopography
sparql:
endpoint: http://localhost/blazegraph/namespace/earthcube/sparql
authenticate: false
username: ""
password: ""
txtaipkg:
endpoint: http://0.0.0.0:8000
Loading

0 comments on commit fe23c00

Please sign in to comment.