Esempio n. 1
0
// GetGeoLinkResource for GeoLink All Hands Demo, remove afterwards, dont' want person specific version
func GetGeoLinkResource(uri string) *sparql.Results {
	log.Printf("GetGeoLinkResource: %s\n", uri)

	repo, err := sparql.NewRepo("http://data.geolink.org/sparql",
		sparql.Timeout(time.Millisecond*15000),
	)
	if err != nil {
		log.Printf("%s\n", err)
	}

	f := bytes.NewBufferString(queries)
	bank := sparql.LoadBank(f)

	// q, err := bank.Prepare("my-query", struct{ Limit, Offset int }{10, 100})
	q, err := bank.Prepare("geolinkperson", struct{ URI string }{uri})
	if err != nil {
		log.Printf("%s\n", err)
	}

	res, err := repo.Query(q)
	if err != nil {
		log.Printf("%s\n", err)
	}

	return res //  Just a test return, would not be what I really return
}
Esempio n. 2
0
// GetRDFResource takes a URI as an arugment and returns information about the RDF resource
func GetRDFResource(uri string) *sparql.Results {
	log.Printf("GetRDFResource: %s\n", uri)

	repo, err := sparql.NewRepo("http://data.oceandrilling.org/sparql",
		sparql.Timeout(time.Millisecond*15000),
	)
	if err != nil {
		log.Printf("%s\n", err)
	}

	f := bytes.NewBufferString(queries)
	bank := sparql.LoadBank(f)

	// q, err := bank.Prepare("my-query", struct{ Limit, Offset int }{10, 100})
	q, err := bank.Prepare("generic", struct{ URI string }{uri})
	if err != nil {
		log.Printf("%s\n", err)
	}

	res, err := repo.Query(q)
	if err != nil {
		log.Printf("%s\n", err)
	}

	// // Print loop testing
	// bindingsTest := res.Results.Bindings // map[string][]binding
	// fmt.Println("res.Resuolts.Bindings:")
	// for k, i := range bindingsTest {
	// 	fmt.Printf("At postion %v with %v and %v\n", k, i["pro"], i["vol"])
	// }

	// bindingsTest2 := res.Bindings() // map[string][]rdf.Term
	// fmt.Println("res.Bindings():")
	// for k, i := range bindingsTest2 {
	// 	fmt.Printf("At postion %v with %v \n", k, i)
	// }

	// solutionsTest := res.Solutions() // map[string][]rdf.Term
	// fmt.Println("res.Solutions():")
	// for k, i := range solutionsTest {
	// 	fmt.Printf("At postion %v with %v \n", k, i)
	// }

	return res //  Just a test return, would not be what I really return
}
Esempio n. 3
0
// TODO ..  error nice if I don't get what I expect in these params
func MaxAge(leg string, site string, hole string) float64 {
	repo, err := sparql.NewRepo("http://data.oceandrilling.org/sparql",
		//sparql.DigestAuth("dba", "dba"),
		sparql.Timeout(time.Millisecond*15000),
	)
	if err != nil {
		log.Print(err)
	}

	f := bytes.NewBufferString(queries)
	bank := sparql.LoadBank(f)

	fmt.Printf("Making call for %s %s %s\n", leg, site, hole)

	q, err := bank.Prepare("agemodel", struct{ URI string }{fmt.Sprintf("<http://data.oceandrilling.org/codices/lsh/%s/%s/%s>", leg, site, hole)})
	if err != nil {
		log.Print(err)
	}

	res, err := repo.Query(q)
	if err != nil {
		log.Print(err)
	}

	maxage := 0.0
	solutionsTest := res.Solutions() // map[string][]rdf.Term
	for _, i := range solutionsTest {
		age, err := strconv.ParseFloat(fmt.Sprint(i["age"]), 64)
		if err != nil {
			log.Print(err)
		}
		if age > maxage {
			maxage = age
		}
	}

	fmt.Println("res.Solutions():")
	for k, i := range solutionsTest {
		fmt.Printf("At postion %v with %v \n", k, i)
	}

	return maxage

}
Esempio n. 4
0
func ExpPublications(queryterm string) string {
	repo, err := sparql.NewRepo("http://data.oceandrilling.org/sparql",
		//sparql.DigestAuth("dba", "dba"),
		sparql.Timeout(time.Millisecond*15000),
	)
	if err != nil {
		log.Print(err)
	}

	f := bytes.NewBufferString(queries)
	bank := sparql.LoadBank(f)

	// q, err := bank.Prepare("my-query", struct{ Limit, Offset int }{10, 100})
	q, err := bank.Prepare("legcall", struct{ Leg string }{"113"})
	if err != nil {
		log.Print(err)
	}

	res, err := repo.Query(q)
	if err != nil {
		log.Print(err)
	}

	// Print loop testing
	bindingsTest := res.Results.Bindings // map[string][]rdf.Term
	fmt.Println("res.Resuolts.Bindings:")
	for k, i := range bindingsTest {
		fmt.Printf("At postion %v with %v and %v\n", k, i["pro"], i["vol"])
	}

	bindingsTest2 := res.Bindings() // map[string][]rdf.Term
	fmt.Println("res.Bindings():")
	for k, i := range bindingsTest2 {
		fmt.Printf("At postion %v with %v \n", k, i)
	}

	solutionsTest := res.Solutions() // map[string][]rdf.Term
	fmt.Println("res.Solutions():")
	for k, i := range solutionsTest {
		fmt.Printf("At postion %v with %v \n", k, i)
	}

	return q
}
Esempio n. 5
0
func LegSite() *sparql.Results {
	repo, err := sparql.NewRepo("http://data.oceandrilling.org/sparql",
		//sparql.DigestAuth("dba", "dba"),
		sparql.Timeout(time.Millisecond*15000),
	)
	if err != nil {
		log.Print(err)
	}

	f := bytes.NewBufferString(queries)
	bank := sparql.LoadBank(f)

	q, err := bank.Prepare("legcall2")
	if err != nil {
		log.Print(err)
	}

	res, err := repo.Query(q)
	if err != nil {
		log.Print(err)
	}

	// Print loop testing
	bindingsTest := res.Results.Bindings // map[string][]rdf.Term
	fmt.Println("res.Resuolts.Bindings:")
	for k, i := range bindingsTest {
		fmt.Printf("At postion %v with %v and %v\n", k, i["p"], i["o"])
	}

	bindingsTest2 := res.Bindings() // map[string][]rdf.Term
	fmt.Println("res.Bindings():")
	for k, i := range bindingsTest2 {
		fmt.Printf("At postion %v with %v \n", k, i)
	}

	solutionsTest := res.Solutions() // map[string][]rdf.Term
	fmt.Println("res.Solutions():")
	for k, i := range solutionsTest {
		fmt.Printf("At postion %v with %v \n", k, i)
	}

	return res

}
Esempio n. 6
0
func AgeModel(leg string, site string, hole string) *sparql.Results {
	repo, err := sparql.NewRepo("http://data.oceandrilling.org/sparql",
		//sparql.DigestAuth("dba", "dba"),
		sparql.Timeout(time.Millisecond*15000),
	)
	if err != nil {
		log.Print(err)
	}

	f := bytes.NewBufferString(queries)
	bank := sparql.LoadBank(f)

	q, err := bank.Prepare("agemodel", struct{ URI string }{fmt.Sprintf("<http://data.oceandrilling.org/codices/lsh/%s/%s/%s>", leg, site, hole)})
	if err != nil {
		log.Print(err)
	}

	res, err := repo.Query(q)
	if err != nil {
		log.Print(err)
	}

	// Print loop testing
	bindingsTest := res.Results.Bindings // map[string][]rdf.Term
	fmt.Println("res.Resuolts.Bindings:")
	for k, i := range bindingsTest {
		fmt.Printf("At postion %v with %v and %v\n", k, i["p"], i["o"])
	}

	bindingsTest2 := res.Bindings() // map[string][]rdf.Term
	fmt.Println("res.Bindings():")
	for k, i := range bindingsTest2 {
		fmt.Printf("At postion %v with %v \n", k, i)
	}

	solutionsTest := res.Solutions() // map[string][]rdf.Term
	fmt.Println("res.Solutions():")
	for k, i := range solutionsTest {
		fmt.Printf("At postion %v with %v \n", k, i)
	}

	return res

}
Esempio n. 7
0
func main() {
	// Init bufferpool, used for rendering templates
	bufpool = bpool.NewBufferPool(48)

	// Load config file
	if _, err := toml.DecodeFile("config.ini", &conf); err != nil {
		log.Fatal("Couldn't parse config file: ", err)
	}

	// Setup remote repository
	repo = newRepo(
		conf.QuadStore.Endpoint,
		time.Duration(conf.QuadStore.OpenTimeout)*time.Millisecond,
		time.Duration(conf.QuadStore.ReadTimeout)*time.Millisecond,
	)

	// Parse Query bank
	qBank = sparql.LoadBank(bytes.NewBufferString(queries))

	// Register metrics
	status = registerMetrics()

	// HTTP routing
	mux := http.NewServeMux()
	var handler mainHandler
	mux.HandleFunc("/robots.txt", serveFile("data/robots.txt"))
	mux.HandleFunc("/css/styles.css", serveFile("data/css/styles.css"))
	mux.HandleFunc("/favicon.ico", serveFile("data/favicon.ico"))
	mux.HandleFunc("/.status", statusHandler)
	mux.HandleFunc("/literals", literalsHandler)
	mux.Handle("/", Timed(CountedByStatusXX(handler, "status", metrics.DefaultRegistry),
		"responseTime",
		metrics.DefaultRegistry))

	fmt.Printf("Listening on port %d ...\n", conf.ServePort)
	err := http.ListenAndServe(fmt.Sprintf(":%d", conf.ServePort), handlers.CompressHandler(mux))
	if err != nil {
		log.Println(err)
	}
}
Esempio n. 8
0
// Had problem with this due to likely some issues now resolved with SPARQL library
func CSIROCall(age string) *sparql.Results {
	repo, err := sparql.NewRepo("http://resource.geosciml.org/sparql/isc2014",
		sparql.Timeout(time.Millisecond*15000),
	)
	if err != nil {
		log.Printf("%s\n", err)
	}

	f := bytes.NewBufferString(queries)
	bank := sparql.LoadBank(f)

	q, err := bank.Prepare("csiro", struct{ Age string }{age})
	if err != nil {
		log.Printf("%s\n", err)
	}

	res, err := repo.Query(q)
	if err != nil {
		log.Printf("%s\n", err)
	}

	return res
}
Esempio n. 9
0
func SPARQLCall(leg string, site string, hole string, query string, endpoint string) *sparql.Results {
	repo, err := sparql.NewRepo(endpoint,
		sparql.Timeout(time.Millisecond*15000),
	)
	if err != nil {
		log.Printf("%s\n", err)
	}

	f := bytes.NewBufferString(queries)
	bank := sparql.LoadBank(f)

	q, err := bank.Prepare(query, struct{ Leg, Site, Hole string }{leg, site, hole})
	if err != nil {
		log.Printf("%s\n", err)
	}

	res, err := repo.Query(q)
	if err != nil {
		log.Printf("%s\n", err)
	}

	return res
}