Building a Recommendation Engine with Java EE

Post on 28-Jan-2018

568 views 1 download

Transcript of Building a Recommendation Engine with Java EE

Building a Recommendation Engine with Java EE EE4J

Otávio Santana@otaviojavaosantana@tomitribe.comotaviojava@apache.org

Hilmer Chona@hchonahilac@msn.comMedellinJUG.org

Evolution

Goods

● Land● Gold● Oil● Information

Machines

The information is not enough

Big Data

Web 3.0Web Semantic

Next?

Recommendation

JCP

Ajax

Search

Collecting

Filtering

Stark

Rogers

Romanoff

Banners

Berlin

São Paulo

Moscow

San Francisco

Medellin

Travel

Stark

Rogers

Romanoff

Banners

New York

São Paulo

Moscow

San Francisco

Medellin

Travel

BusinessFun

Reasons why travel

1. Fun2. Conferences3. Music4. Geek Conf5. Family6. History7. Language8. Honeymoon9. Work

10. Meetings11. University12. Shopping13. Relax

More Information

name Tony Stark

nationality American

hero Iron man

power rich

when 2011

why Save the world

who flying

type Fun

name San Francisco

country USA

State California

Founded 1776

Travels

NoSQL● Database● Doesn't use structure● Not Transaction● BASE● Types

Graph

● Neo4j● InfoGrid● Sones● HyperGraphDB

Apollo Ares

Kratoswas killed by was killed by

Is brother

killed killed

SQL Key-value Column Document Graph

Table Bucket Column Family

Collection

Row Key/value pair

Column Document Vertex

Column Key/value pair

Key/value pair Vertex and Edge property

Relationship Link Edge

SQL vs NoSQL

Scalability vs Complexity

Scalability

Complexity

key-value

Column

Document

Graph

Graph

Grace Hopper

label Person

id ada

name Ada Lovelace

occupation scientist

Ada Lovelace

label Person

id grace

name Grace Hopper

occupation scientist

Knows

Vertex Vertex

Edge

Graph Database

TinkerPop

http://tinkerpop.apache.org/

TinkerPop

Grace Hopper

label Person

id grace

name Grace Hopper

occupation scientist

Vertex

grace = graph.addVertex( T.label, "person", "id", "grace", "name", "Grace Hopper", "occupation", "scientist");

TinkerPop

Grace Hopper

Ada Lovelace

Knows

grace.addEdge("knows", ada);

Edges

Out ->

In <-

Both

Marketing Campaign● Engineer● Salary 3000● Age between 20 and 25 years

SQLId name Occupation Salary age gender

... ... ... ... ... ...

SELECT * FROM Person WHERE

occupation = "Engineer" AND

salary > 3000 and age BETWEEN 20

AND 25

TinkerPopGrace Hopper

Ada Lovelace

Knows

g.V().has("occupation","Engineer").has("salary", gt(3000)).has("age", between(20, 25));

Their Friends

SQLId name Occupation Salary age gender

... ... ... ... ... ...

SELECT * FROM Person WHERE

occupation = "Engineer" AND

salary > 3000 and age BETWEEN 20

AND 25//...joins

Id know

... ...

TinkerPopGrace Hopper

Ada Lovelace

Knows

g.V().has("occupation","Engineer").has("salary", gt(3000)).has("age", between(20, 25)).out("knows");

Falling in love

SQLId name Occupation Salary age gender

... ... ... ... ... ...

SELECT * FROM Person WHERE

occupation = "Engineer" AND

salary > 3000 and age BETWEEN 20

AND 25//...joins

Id know

... ...

Id love

... ...

TinkerPopGrace Hopper

Ada Lovelace

Knows

g.V().has("occupation","Engineer").has("salary", gt(3000)).has("age", between(20, 25)).outE("knows").has("feel", "love").bothV();

JNoSQL

● Mapping API● Communication API● No lock-in● Divide and conquer

DAO

Mapping

Communication

DocumentKey

Column Graph

DIANA

ARTEMIS

JNoSQL

Data Tier

Artemis● CDI Based● Diana Based● Annotation Based● Events to insert, delete, update● Supports to Bean Validation● Configurable and Extensible● Query Method

Graph Database

Graph

Poliana

label Book

age 2007

name The Shack

The Shack

label Person

name Poliana

age 25

reads

where Brazil

Graph

Person poliana = graphTemplate.insert(Person.builder().withName("Poliana").withAge(25).build());

Book shack = graphTemplate.insert(Book.builder().withAge(2007).withName("The Shack").build());

EdgeEntity<Person, Book> reads = graphTemplate.edge(poliana, "reads", shack);reads.add("where", "Brazil");

Marketing Campaign● Engineer● Salary 3000● Age between 20 and 25 years

Developers

List<Person> developers = graph.getTraversalVertex() .has("salary", gte(3_000D)) .has("age", between(20, 25)) .has("occupation", "Developer") .<Person>stream().collect(toList());

Their Friends

People who developer knows

List<Person> result = graph.getTraversalVertex() .has("salary", gte(3_000D)) .has("age", between(20, 25)) .has("occupation", "Developer") .out("knows")

Falling in love

People who developer loves

List<Person> love = graph.getTraversalVertex() .has("salary", gte(3_000D)) .has("age", between(20, 25)) .has("occupation", "Developer") .outE("knows") .has("feel", "love") .bothV() .<Person>stream() .distinct() .collect(toList());

Book Recommendation

Software

Romance

NoSQL

Java

Micro Services

Effective Java

The Shack

Migrating to Microservice Databases

NoSQL Distilled

Software Categories

List<String> result = graph.getTraversalVertex() .hasLabel("Category") .has("name", "Software") .in("is") .hasLabel("Category").<Category>stream() .map(Category::getName) .collect(toList());

Query Methodinterface PersonRepository extends Repository<Person, Long> {

List<Person> findByAddress(String address);

Stream<Person> findByName(String name);

Stream<Person> findByNameAndKnowsOutV(String name);

Stream<Person> findByNameAndBothV(String name, String label);

Optional<Person> findByNickname(String nickname);

void deleteByNickName(String nickname);}

DemoJNoSQL

Configuration

CDI 2.0 with Java SE

Neo4J + Docker

Thank You

Otávio Santana@otaviojavaosantana@tomitribe.comotaviojava@apache.org

Hilmer Chona@hchonahilac@msn.com