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

Author/nishidanaoto part #44

Merged
merged 3 commits into from
Aug 28, 2020
Merged
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
58 changes: 57 additions & 1 deletion src/main/java/com/example/demo/controller/HtmlController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,35 @@
import java.util.ArrayList;
import java.util.List;


/**
* @author Naoto Nishida
*/
@Controller
@RequestMapping(path = "/")
public class HtmlController {

@Autowired
EmologService emologService;

/**
* @author Naoto Nishida
*/
@RequestMapping(path = "/", method = RequestMethod.GET)
public String index() {
return "friendlist";
}

/**
* @author Naoto Nishida
*/
@RequestMapping(path = "/emologlist", method = RequestMethod.GET)
public String emologlist() {
return "emologlist";
}

/**
* @author Naoto Nishida
*/
//この処理いる?バッチ処理できたらいらなそうな気がする。
@RequestMapping(path = "/enter", method = RequestMethod.GET)
public String crawling(
Expand All @@ -40,6 +51,51 @@ public String crawling(

emologService.createEmolog();

//previous実装.バッチ処理したからいらなくなった。
/**
* List<String> keyword_tweets = new ArrayList<String>();
* List<String> keyword_images = new ArrayList<String>();
*
* keyword_tweets = ViewController.get_NLU_keywords("CNN", 100000);
* keyword_images = ViewController.get_image_keywords("CNN", 100000);
*
* List<String> emojiList = new ArrayList<String>();
*
* // TODO: ここでDBアクセスかなんかlook upする??。->つかささんのやつくっつける。
*
* // 文字列整形の方(テキトーに::をつける方)
* for( String keyword : keyword_tweets){
* try{
* String tmp = EmojiParser.parseToHtmlDecimal(":" + keyword + ":");
* emojiList.add(tmp);
* }
* catch (NullPointerException ignored){}
* }
*
* for( String keyword : keyword_images){
* try{
* String tmp = EmojiParser.parseToHtmlDecimal(":" + keyword + ":");
* emojiList.add(tmp);
* }
* catch (NullPointerException ignored){}
* }
*
* // で、:hoge:みたいなんが得られたらEmologにパースして、それをaddAttributeする.->データがdbに入っていないとThymeleaf側で取り出せん模様。
* // modelMap.addAttribute("emologs", emojiList);
*
*
* // emojiList : ["&#128515", "&#128515", "&#128515"] みたいな感じ。
* // emojiListから一つの文字列に直す。
* String emolog = String.join("", emojiList);
*
*
* //TODO: ここで得られたemologをdbに登録する処理…
* // emolog(userid, friendid, create_at, contents)
* // userid = 1, friendid = 2, create_at = TIMESTAMP??, contents = emolog
*
* return "friendlist";
*/

return "friendlist";
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/example/demo/controller/TwitterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@

import java.io.IOException;

/**
* @author Naoto Nishida
*/
@RestController
@RequestMapping(path = "/twitter")
public class TwitterController {

/**
* @author Naoto Nishida
*/
@GetMapping("/search_keyword")
public QueryResult search_keyowrd(@RequestParam(name = "searchword", defaultValue = "チンチン") String searchword) throws TwitterException {
public QueryResult search_keyowrd(@RequestParam(name = "searchword", defaultValue = "judo") String searchword) throws TwitterException {
// 初期化
Twitter twitter = new TwitterFactory().getInstance();
Query query = new Query(searchword);
Expand All @@ -27,6 +33,9 @@ public QueryResult search_keyowrd(@RequestParam(name = "searchword", defaultValu
return result;
}

/**
* @author Naoto Nishida
*/
@RequestMapping(path = "/search_user", method = RequestMethod.GET)
public QueryResult search_user(@RequestParam(name = "username", defaultValue = "CNN") String username,
@RequestParam(name = "tweet_id", defaultValue = "1000000") long tweet_id
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/example/demo/controller/ViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public String read(@PathVariable("id") String id) {
return list.toString();
}

/**
* @author Naoto Nishida
*/
//TODO: Controllerのままか、返り値の型の調整どうするか考える(フロントとの兼ね合い。)
@RequestMapping(path = "/twitter_NLU_keyword", method = RequestMethod.GET)
public List<String> collect_NLU_keywords_from_tweets(
Expand All @@ -72,7 +75,9 @@ public List<String> collect_NLU_keywords_from_tweets(
//TODO: 整形する必要あるかも?
}


/**
* @author Naoto Nishida
*/
@RequestMapping(path = "/twitter_image_keyword", method = RequestMethod.GET)
public List<String> collect_image_keywords_from_tweets(
@RequestParam(name = "username", defaultValue = "CNN") String username,
Expand All @@ -98,6 +103,9 @@ public List<String> collect_image_keywords_from_tweets(

}

/**
* @author Naoto Nishida
*/
// コントローラは関数として呼び出すのはキツイっぽいのでとりま関数として取り出してる。。
//TODO: TwitterControllerやNLUControllerから共通部分を分離して別クラスとして保持。
private static QueryResult search_user(String username, long tweet_id) throws TwitterException {
Expand Down Expand Up @@ -197,6 +205,9 @@ public List<Emolog> insertEmolog(
return emologService.insert(123, 456, "U+1F600");
}

/**
* @author Naoto Nishida
*/
//関数もおいちゃえ
public static List<String> get_NLU_keywords(String username, long tweet_id) throws TwitterException {
QueryResult result = search_user(username, tweet_id);
Expand All @@ -215,6 +226,9 @@ public static List<String> get_NLU_keywords(String username, long tweet_id) thro
}


/**
* @author Naoto Nishida
*/
public static List<String> get_image_keywords(String username, long tweet_id) throws Exception {
QueryResult result = search_user(username, tweet_id);
ArrayList<String> imageprocessing_results = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/service/EmologService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void createEmolog() throws Exception {
LocalDateTime created_at = LocalDateTime.now();
int count = 0;
for (Friend friend : friends) {
//////////
//
//TODO: 「取得した最新のtweet_idを保存して次のバッチ処理ではそのtweet_id以降を取得」って処理がまだ出来てない。
try {
QueryResult result = emologOutput.querySearch(friend.getName(), friend.getLasttweetid());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/emologlist.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!--西田担当分。Thymeleaf記述あたりのサポート-->
<!DOCTYPE html>
<html lang="jp" dir="ltr" xmlns:th="http://www.thymeleaf.org">
<head>
Expand Down