예제 #1
0
/*
* Searches for articles in the database
* @param tags string[] The tags entered by the user.Currently only entity search has been implemented.
Algorithm in Readme
*/
func SearchForArticles(tags []string, store *cayley.Handle) PairList {
	links := make(map[string]int)

	for _, tag := range tags {

		entities := extractArticleData.GetEntityInfo(tag, "")

		if len(entities) == 0 {
			continue
		}

		entitityInfo := entities[0] // Get the First Entity //TODO:- Change to Best Label Match

		for _, category := range entitityInfo.Categories {

			path := cayley.StartPath(store, category).
				In("has_category").
				In("has_entity")

			it := path.BuildIterator()
			it, _ = it.Optimize()

			for cayley.RawNext(it) {
				link := store.NameOf(it.Result())
				links[link] += 10
			}
		}
	}
	return sortMapByValue(links)
}
예제 #2
0
func (p *mgoPersistenceProvider) loadVersionsByAPI(apiVersion string, graph *cayley.Handle, session *mgo.Session, target common.IServiceRegistry) error {
	var startingNodeID = utils.CreateAPIVersionKey(apiVersion)
	var path = cayley.StartPath(graph, startingNodeID).Out(utils.ContainsVersionRel)
	it := path.BuildIterator()
	for cayley.RawNext(it) {
		var version serviceVersion
		err := session.DB("test").C("serviceVersions").Find(bson.M{"_id": graph.NameOf(it.Result())}).One(&version)
		if err != nil {
			return err
		}
		target.LinkServiceToAPI(version.Service, version.Version, apiVersion)
	}

	return nil
}
예제 #3
0
func (p *mgoPersistenceProvider) loadVersionsByService(serviceIdentifier string, graph *cayley.Handle, session *mgo.Session, target common.IServiceRegistry) error {
	var startingNodeID = utils.CreateServiceDefinitionKey(serviceIdentifier)
	var path = cayley.StartPath(graph, startingNodeID).Out(utils.ContainsVersionRel)
	it := path.BuildIterator()
	for cayley.RawNext(it) {
		var version serviceVersion
		var serviceVersionNode = graph.NameOf(it.Result())
		err := session.DB("test").C("serviceVersions").Find(bson.M{"_id": serviceVersionNode}).One(&version)
		if err != nil {
			return fmt.Errorf("Cannot find %s in collection 'serviceVersions': %s", serviceVersionNode, err.Error())
		}
		target.AddServiceVersion(serviceIdentifier, version.Version)
	}

	return nil
}
예제 #4
0
func GetInfoForLink(store *cayley.Handle, link string) Article {
	path := cayley.StartPath(store, link).
		Save("has_title", "title").
		Save("has_description", "description")

	it := path.BuildIterator()
	it, _ = it.Optimize()

	graph.Next(it)
	tags := make(map[string]graph.Value)
	it.TagResults(tags)
	return Article{
		store.NameOf(tags["title"]),
		store.NameOf(tags["description"]),
		link,
	}
}
예제 #5
0
/*
	The root page.Gets Data from the database to Display articles
*/
func mainHandler(w http.ResponseWriter, r *http.Request, store *cayley.Handle) {

	t, error := template.ParseFiles("website/templates/index.html")

	if error != nil {
		fmt.Println("error:", error)
		fmt.Println("HTML TEMPLATE WAS NOT FOUND. Check if the html file is present.")

	}

	path := cayley.StartPath(store, "Article").
		In().
		Tag("link").
		Save("has_image", "image").
		Save("has_title", "title").
		Save("has_description", "description")

	it := path.BuildIterator()
	it, _ = it.Optimize()

	articleList := make([]Article, 0)

	for graph.Next(it) {
		tags := make(map[string]graph.Value)
		it.TagResults(tags)

		articleList = append(articleList, Article{
			store.NameOf(tags["title"]),
			store.NameOf(tags["description"]),
			store.NameOf(tags["link"]),
			store.NameOf(tags["image"]),
		})

	}

	type PageContent struct {
		Articles []Article
	}

	t.Execute(w, PageContent{articleList})
}
예제 #6
0
/*
Calls the extractArticleData package to obtain Article Data and then adds the information to the database
*/
func submitLink(w http.ResponseWriter, r *http.Request, store *cayley.Handle) {

	data := extractArticleData.GetDataFromArticle(r.FormValue("UploadLink"))

	store.AddQuad(cayley.Quad(data.Link, "has_parent", data.Parent, ""))
	store.AddQuad(cayley.Quad(data.Link, "has_date", data.Date, ""))
	store.AddQuad(cayley.Quad(data.Link, "has_content", data.Content, ""))
	store.AddQuad(cayley.Quad(data.Link, "has_title", data.Title, ""))
	store.AddQuad(cayley.Quad(data.Link, "has_description", data.Description, ""))
	store.AddQuad(cayley.Quad(data.Link, "has_image", data.Image, ""))

	for _, entity := range data.Entities {

		store.AddQuad(cayley.Quad(data.Link, "has_entity", entity.Name, ""))
		for _, class := range entity.Classes {
			store.AddQuad(cayley.Quad(entity.Name, "has_class", class, ""))

		}

		for _, category := range entity.Categories {
			store.AddQuad(cayley.Quad(entity.Name, "has_category", category, ""))
		}

	}

}