Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tsukasa #34

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions demo.iml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" version="4">
<component name="FacetManager">
<facet type="jpa" name="JPA">
<configuration>
<setting name="validation-enabled" value="true" />
<setting name="provider-name" value="Hibernate" />
<datasource-mapping>
<factory-entry name="entityManagerFactory" />
</datasource-mapping>
<datasource-mapping />
<naming-strategy-map />
</configuration>
</facet>
Expand Down Expand Up @@ -37,10 +35,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="twitter4j-async-4.0.7" level="project" />
<orderEntry type="library" name="twitter4j-core-4.0.7" level="project" />
<orderEntry type="library" name="twitter4j-examples-4.0.7" level="project" />
<orderEntry type="library" name="twitter4j-stream-4.0.7" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-thymeleaf:2.3.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.3.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.3.2.RELEASE" level="project" />
Expand Down Expand Up @@ -177,6 +171,5 @@
<orderEntry type="library" name="Maven: org.seasar.doma:doma:2.18.0" level="project" />
<orderEntry type="library" name="Maven: com.vdurmont:emoji-java:4.0.0" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20170516" level="project" />

</component>
</module>
39 changes: 30 additions & 9 deletions docker/pg/1-createTable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ create table users (
filterlevel smallint
);

insert into users(name, mail, filterlevel) values
('ichigo.chocomint', '[email protected]', 1),
('banana.chocomint', '[email protected]', 2),
('pinapple.chocomint', '[email protected]', 3)
;

create table sample (
id serial primary key,
name varchar(30) not null,
mail varchar(50) not null,
filterlevel smallint
);

insert into sample(name, mail, filterlevel) values
('ichigo.chocomint', '[email protected]', 1),
('banana.chocomint', '[email protected]', 2),
('pinapple.chocomint', '[email protected]', 3)
;

create table friend (
id serial primary key,
userid INTEGER not null,
Expand All @@ -20,6 +32,12 @@ create table friend (
updated_at timestamp
);

insert into friend(userid, name, latestemolog, updated_at) values
(123, 'ichigo.chocomint', '🍎🍋🍇', 2020-08-24 16:24:29.353806),
(456, 'banana.chocomint', '🍈🍓🍌', 2020-08-25 16:24:29.353806),
(789, 'pinapple.chocomint', '🍊🥝', 2020-08-26 16:24:29.353806)
;

create table emolog (
id serial primary key,
userid INTEGER not null,
Expand All @@ -28,6 +46,10 @@ create table emolog (
contents varchar(30)
);

insert into emolog(userid, friendid, created_at, contents) values
(123, 456, 2020-08-26 16:24:29.353806, U+1F600)
;

create table talk (
id serial primary key,
userid INTEGER not null,
Expand All @@ -36,6 +58,10 @@ create table talk (
create_at timestamp
);

insert into talk(userid, friendid, contents, create_at) values
(123, 456, "こんにちは", 2020-08-26 16:24:29.353806)
;

create table requestfriend (
id serial primary key,
userid INTEGER not null,
Expand All @@ -44,17 +70,12 @@ create table requestfriend (
create_at timestamp
);

insert table requestfriend() values
()
;

create table emojicode (
keyword serial primary key,
emoji_code varchar(30)
);

insert into users(name, mail, filterlevel) values
('ichigo.chocomint', '[email protected]', 1),
('banana.chocomint', '[email protected]', 2),
('pinapple.chocomint', '[email protected]', 3)
;

insert into emolog(userid, friendid, name, latestemolog)
values (1, 2, 'hoge', 'emojihoge')
;
15 changes: 8 additions & 7 deletions src/main/java/com/example/demo/controller/ImageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,29 @@
import java.io.File;

@RestController
@RequestMapping(path = "/Image")
@RequestMapping(path = "/image")
public class ImageController {
private static final Logger LOG = LoggerFactory.getLogger(ImageController.class);

@Autowired
JdbcTemplate jdbcTemplate;

@RequestMapping(path = "/test", method = RequestMethod.GET)
@RequestMapping(path = "/recognition", method = RequestMethod.GET)
public String test(
@RequestParam(name = "img_path", defaultValue = "/Users/NakamuraTsukasa/Desktop/633.png") String img_path
@RequestParam(name = "img_path", defaultValue = "/Users/NakamuraTsukasa/Desktop/633.png") String img_path,
@RequestParam(name = "img_url", defaultValue = "https://upload.wikimedia.org/wikipedia/commons/2/2a/Jewelkatz_Romeo_Of_Stalker-Bars.jpg") String img_url
) throws FileNotFoundException {
String url = "https://zukan.pokemon.co.jp/zukan-api/up/images/index/94b9fb82b38847b83a8041e9a78989ce.png";
//String url = "https://zukan.pokemon.co.jp/zukan-api/up/images/index/94b9fb82b38847b83a8041e9a78989ce.png";

IamAuthenticator authenticator = new IamAuthenticator("8nwN0eKp7eZ73So4DLdPndp_yv-vtlI27pN1wK2TjVg1");
VisualRecognition visualRecognition = new VisualRecognition("2019-07-12", authenticator);

ClassifyOptions options = new ClassifyOptions.Builder()
// .url(url)
.imagesFile(new File(img_path))
.url(img_url)
//.imagesFile(new File(img_path))
.build();
ClassifiedImages result = visualRecognition.classify(options).execute().getResult();
System.out.println(result);
//System.out.println(result);

List<ClassifiedImage> images = result.getImages();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.demo.controller;

import com.example.demo.entity.Emolog;
import com.example.demo.entity.Sample;
import com.example.demo.service.EmologService;
import com.example.demo.service.SampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/example/demo/controller/ViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.lang.NullPointerException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.example.demo.entity.Emolog;
import com.example.demo.service.EmologService;
import com.ibm.cloud.sdk.core.security.IamAuthenticator;
import com.ibm.watson.natural_language_understanding.v1.NaturalLanguageUnderstanding;
import com.ibm.watson.natural_language_understanding.v1.model.*;
import com.ibm.watson.visual_recognition.v3.VisualRecognition;
import com.ibm.watson.visual_recognition.v3.model.*;
import com.vdurmont.emoji.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,6 +33,9 @@ public class ViewController {
@Autowired
JdbcTemplate jdbcTemplate;

@Autowired
EmologService emologService;

@RequestMapping(path = "/users", method = RequestMethod.GET)
public String index() {
List<Map<String, Object>> list;
Expand Down Expand Up @@ -161,4 +169,34 @@ private String ImageProcessing(String url) throws FileNotFoundException {

}

//emoji-javaを使ってキーワードから絵文字に変換
@RequestMapping(path = "/convert/{keyword}", method = RequestMethod.GET)
public String convert(
@PathVariable("keyword") String keyword
) {
keyword = keyword.replace(" ", "_"); //空白を_に置換
keyword = ":" + keyword + ":";
Emoji emoji;
try {
emoji = EmojiManager.getForAlias(keyword);
System.out.println(emoji);
return emoji.getUnicode();
} catch(java.lang.NullPointerException n) {
//キーワードがエイリアスとして存在していないときは?を返す
System.out.println(n);
emoji = EmojiManager.getForAlias("grey_question");
return emoji.getUnicode();
}
}

@RequestMapping(value="/emolog",method=RequestMethod.GET)
public List<Emolog> insertEmolog(
Integer user,
Integer friend,
String emoji
) throws ParseException {
// return emologService.insert(user, friend, emoji);
return emologService.insert(123, 456, "U+1F600");
}

}
3 changes: 3 additions & 0 deletions src/main/java/com/example/demo/dao/EmologDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public interface EmologDao {

@Select
List<Emolog> selectAll(int user, int friend);

@Insert
int insert(Emolog e);
}
3 changes: 2 additions & 1 deletion src/main/java/com/example/demo/entity/Emolog.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public class Emolog implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
//@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@NotNull

@Size(max=30)
private Integer userid;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public class EmologRepository {
public List<Emolog> selectAll(int user, int friend) { // (4)
return dao.selectAll(user, friend);
}

@Insert
public int insert(Emolog e) {
return dao.insert(e);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/example/demo/service/EmologService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -21,4 +26,17 @@ public class EmologService {
public List<Emolog> selectAll(int user, int friend){
return repository.selectAll(user, friend);
}

public List<Emolog> insert(int user, int friend, String contents) throws ParseException {
Emolog e = new Emolog();
e.setId(13);
e.setUserid(user);
e.setFriendid(friend);
LocalDateTime create_at = LocalDateTime.now();
e.setCreate_at(create_at);
e.setContents(contents);
repository.insert(e);
return repository.selectAll(user, friend);
}

}
Binary file modified target/classes/com/example/demo/DemoApplication.class
Binary file not shown.
Binary file modified target/classes/com/example/demo/controller/ViewController.class
Binary file not shown.
Binary file removed target/classes/com/example/demo/entity/View.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.