further update to bot being moved to new sys machine
This commit is contained in:
parent
84396ef56c
commit
efd3a671c4
@ -1,42 +1,42 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package DataLayer;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import DataLayer.settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DBCPDataSource {
|
||||
private static BasicDataSource ds = new BasicDataSource();
|
||||
static {
|
||||
try {
|
||||
ds.setDriver(new com.mysql.cj.jdbc.Driver());
|
||||
ds.setUrl(settings.url);
|
||||
ds.setUsername(settings.username);
|
||||
ds.setPassword(settings.password);
|
||||
ds.setMaxTotal(-1);
|
||||
ds.setMinIdle(5);
|
||||
ds.setMaxIdle(-1);
|
||||
ds.setMaxOpenPreparedStatements(100);
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DBCPDataSource.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return ds.getConnection();
|
||||
}
|
||||
|
||||
private DBCPDataSource() {
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package DataLayer;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import DataLayer.settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DBCPDataSource {
|
||||
private static BasicDataSource ds = new BasicDataSource();
|
||||
static {
|
||||
try {
|
||||
ds.setDriver(new com.mysql.cj.jdbc.Driver());
|
||||
ds.setUrl(settings.url);
|
||||
ds.setUsername(settings.username);
|
||||
ds.setPassword(settings.password);
|
||||
ds.setMaxTotal(-1);
|
||||
ds.setMinIdle(5);
|
||||
ds.setMaxIdle(-1);
|
||||
ds.setMaxOpenPreparedStatements(100);
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DBCPDataSource.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return ds.getConnection();
|
||||
}
|
||||
|
||||
private DBCPDataSource() {
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package DataLayer;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import DataLayer.settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DBCPDataSourceHLstats {
|
||||
|
||||
private static BasicDataSource ds = new BasicDataSource();
|
||||
static {
|
||||
try {
|
||||
ds.setDriver(new com.mysql.cj.jdbc.Driver());
|
||||
ds.setUrl(settings.hlURL);
|
||||
ds.setUsername(settings.hlusername);
|
||||
ds.setPassword(settings.hlpassword);
|
||||
ds.setMaxTotal(-1);
|
||||
ds.setMinIdle(5);
|
||||
ds.setMaxIdle(-1);
|
||||
ds.setMaxOpenPreparedStatements(100);
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DBCPDataSource.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return ds.getConnection();
|
||||
}
|
||||
|
||||
private DBCPDataSourceHLstats() {
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package DataLayer;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import DataLayer.settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DBCPDataSourceHLstats {
|
||||
|
||||
private static BasicDataSource ds = new BasicDataSource();
|
||||
static {
|
||||
try {
|
||||
ds.setDriver(new com.mysql.cj.jdbc.Driver());
|
||||
ds.setUrl(settings.hlURL);
|
||||
ds.setUsername(settings.hlusername);
|
||||
ds.setPassword(settings.hlpassword);
|
||||
ds.setMaxTotal(-1);
|
||||
ds.setMinIdle(5);
|
||||
ds.setMaxIdle(-1);
|
||||
ds.setMaxOpenPreparedStatements(100);
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DBCPDataSource.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return ds.getConnection();
|
||||
}
|
||||
|
||||
private DBCPDataSourceHLstats() {
|
||||
}
|
||||
}
|
||||
|
@ -1,131 +1,131 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package DataLayer;
|
||||
|
||||
import FunctionLayer.SimilarityMatrix;
|
||||
import FunctionLayer.CustomError;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DataMapper {
|
||||
|
||||
public static void createTables() throws CustomError {
|
||||
Connection l_cCon = null;
|
||||
PreparedStatement l_pStatement = null;
|
||||
ResultSet l_rsSearch = null;
|
||||
try {
|
||||
l_cCon = DBCPDataSource.getConnection();
|
||||
String l_sSQL = "CREATE TABLE IF NOT EXISTS `ArtificialAutism`.`Sentences` (`Strings` text NOT NULL)";
|
||||
l_pStatement = l_cCon.prepareStatement(l_sSQL);
|
||||
l_pStatement.execute();
|
||||
} catch (SQLException ex) {
|
||||
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
||||
} finally {
|
||||
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
||||
}
|
||||
}
|
||||
|
||||
public static ConcurrentMap<Integer, String> getAllStrings() throws CustomError {
|
||||
ConcurrentMap<Integer, String> allStrings = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
Connection l_cCon = null;
|
||||
PreparedStatement l_pStatement = null;
|
||||
ResultSet l_rsSearch = null;
|
||||
try {
|
||||
l_cCon = DBCPDataSource.getConnection();
|
||||
String l_sSQL = "SELECT * FROM `Sentences`";
|
||||
l_pStatement = l_cCon.prepareStatement(l_sSQL);
|
||||
l_rsSearch = l_pStatement.executeQuery();
|
||||
int ij = 0;
|
||||
while (l_rsSearch.next()) {
|
||||
allStrings.put(ij, l_rsSearch.getString(1));
|
||||
ij++;
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
||||
} finally {
|
||||
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
||||
}
|
||||
return allStrings;
|
||||
}
|
||||
|
||||
public static void InsertMYSQLStrings(ConcurrentMap<Integer, String> str) throws CustomError {
|
||||
Connection l_cCon = null;
|
||||
PreparedStatement l_pStatement = null;
|
||||
ResultSet l_rsSearch = null;
|
||||
String l_sSQL = "INSERT IGNORE `Sentences` (`Strings`) VALUES (?)";
|
||||
try {
|
||||
l_cCon = DBCPDataSource.getConnection();
|
||||
l_pStatement = l_cCon.prepareStatement(l_sSQL);
|
||||
for (String str1 : str.values()) {
|
||||
//System.out.println("adding str1: " + str1 + "\n");
|
||||
l_pStatement.setString(1, str1);
|
||||
l_pStatement.addBatch();
|
||||
}
|
||||
l_pStatement.executeBatch();
|
||||
} catch (SQLException ex) {
|
||||
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
||||
} finally {
|
||||
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
||||
}
|
||||
}
|
||||
|
||||
public static ConcurrentMap<Integer, String> getHLstatsMessages() {
|
||||
ConcurrentMap<Integer, String> hlStatsMessages = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
try (Connection l_cCon = DBCPDataSourceHLstats.getConnection()) {
|
||||
String l_sSQL = "SELECT message FROM `hlstats_Events_Chat`";
|
||||
try (PreparedStatement l_pStatement = l_cCon.prepareStatement(l_sSQL)) {
|
||||
try (ResultSet l_rsSearch = l_pStatement.executeQuery()) {
|
||||
while (l_rsSearch.next()) {
|
||||
hlStatsMessages.put(hlStatsMessages.size() + 1, l_rsSearch.getString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return hlStatsMessages;
|
||||
}
|
||||
|
||||
public static void CloseConnections(PreparedStatement ps, ResultSet rs, Connection con) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (ps != null) {
|
||||
try {
|
||||
ps.close();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (con != null) {
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package DataLayer;
|
||||
|
||||
import FunctionLayer.SimilarityMatrix;
|
||||
import FunctionLayer.CustomError;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DataMapper {
|
||||
|
||||
public static void createTables() throws CustomError {
|
||||
Connection l_cCon = null;
|
||||
PreparedStatement l_pStatement = null;
|
||||
ResultSet l_rsSearch = null;
|
||||
try {
|
||||
l_cCon = DBCPDataSource.getConnection();
|
||||
String l_sSQL = "CREATE TABLE IF NOT EXISTS `ArtificialAutism`.`Sentences` (`Strings` text NOT NULL)";
|
||||
l_pStatement = l_cCon.prepareStatement(l_sSQL);
|
||||
l_pStatement.execute();
|
||||
} catch (SQLException ex) {
|
||||
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
||||
} finally {
|
||||
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
||||
}
|
||||
}
|
||||
|
||||
public static ConcurrentMap<Integer, String> getAllStrings() throws CustomError {
|
||||
ConcurrentMap<Integer, String> allStrings = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
Connection l_cCon = null;
|
||||
PreparedStatement l_pStatement = null;
|
||||
ResultSet l_rsSearch = null;
|
||||
try {
|
||||
l_cCon = DBCPDataSource.getConnection();
|
||||
String l_sSQL = "SELECT * FROM `Sentences`";
|
||||
l_pStatement = l_cCon.prepareStatement(l_sSQL);
|
||||
l_rsSearch = l_pStatement.executeQuery();
|
||||
int ij = 0;
|
||||
while (l_rsSearch.next()) {
|
||||
allStrings.put(ij, l_rsSearch.getString(1));
|
||||
ij++;
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
||||
} finally {
|
||||
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
||||
}
|
||||
return allStrings;
|
||||
}
|
||||
|
||||
public static void InsertMYSQLStrings(ConcurrentMap<Integer, String> str) throws CustomError {
|
||||
Connection l_cCon = null;
|
||||
PreparedStatement l_pStatement = null;
|
||||
ResultSet l_rsSearch = null;
|
||||
String l_sSQL = "INSERT IGNORE `Sentences` (`Strings`) VALUES (?)";
|
||||
try {
|
||||
l_cCon = DBCPDataSource.getConnection();
|
||||
l_pStatement = l_cCon.prepareStatement(l_sSQL);
|
||||
for (String str1 : str.values()) {
|
||||
//System.out.println("adding str1: " + str1 + "\n");
|
||||
l_pStatement.setString(1, str1);
|
||||
l_pStatement.addBatch();
|
||||
}
|
||||
l_pStatement.executeBatch();
|
||||
} catch (SQLException ex) {
|
||||
throw new CustomError("failed in DataMapper " + ex.getMessage());
|
||||
} finally {
|
||||
CloseConnections(l_pStatement, l_rsSearch, l_cCon);
|
||||
}
|
||||
}
|
||||
|
||||
public static ConcurrentMap<Integer, String> getHLstatsMessages() {
|
||||
ConcurrentMap<Integer, String> hlStatsMessages = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
try (Connection l_cCon = DBCPDataSourceHLstats.getConnection()) {
|
||||
String l_sSQL = "SELECT message FROM `hlstats_Events_Chat`";
|
||||
try (PreparedStatement l_pStatement = l_cCon.prepareStatement(l_sSQL)) {
|
||||
try (ResultSet l_rsSearch = l_pStatement.executeQuery()) {
|
||||
while (l_rsSearch.next()) {
|
||||
hlStatsMessages.put(hlStatsMessages.size() + 1, l_rsSearch.getString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return hlStatsMessages;
|
||||
}
|
||||
|
||||
public static void CloseConnections(PreparedStatement ps, ResultSet rs, Connection con) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (ps != null) {
|
||||
try {
|
||||
ps.close();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (con != null) {
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class CustomError extends Exception {
|
||||
|
||||
public CustomError(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class CustomError extends Exception {
|
||||
|
||||
public CustomError(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,104 +1,104 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
import PresentationLayer.DiscordHandler;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.TextChannel;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DoStuff {
|
||||
|
||||
public static boolean occupied = false;
|
||||
|
||||
public static boolean isOccupied() {
|
||||
return occupied;
|
||||
}
|
||||
|
||||
public static void doStuff(MessageCreateEvent event, String usernameBot) {
|
||||
String username = null;
|
||||
try {
|
||||
username = event.getMessage().getAuthor().get().getUsername();
|
||||
} catch (java.util.NoSuchElementException e) {
|
||||
username = null;
|
||||
}
|
||||
if (username != null && !username.equals(usernameBot)) {
|
||||
occupied = true;
|
||||
TextChannel block = event.getMessage().getChannel().cast(TextChannel.class).block();
|
||||
String name = block.getCategory().block().getName();
|
||||
name = name.toLowerCase();
|
||||
String channelName = block.getName().toLowerCase();
|
||||
boolean channelpermissionsDenied = false;
|
||||
switch (name) {
|
||||
case "public area": {
|
||||
break;
|
||||
}
|
||||
case "information area": {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
channelpermissionsDenied = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
List<User> blockLast = event.getMessage().getUserMentions().buffer().blockLast();
|
||||
String content = event.getMessage().getContent();
|
||||
if (!channelpermissionsDenied) {
|
||||
if (blockLast != null)
|
||||
{
|
||||
for (User user : blockLast) {
|
||||
content = content.replace(user.getId().asString(), "");
|
||||
}
|
||||
}
|
||||
MessageResponseHandler.getMessage(content);
|
||||
}
|
||||
boolean mentionedBot = false;
|
||||
if (blockLast != null){
|
||||
for (User user : blockLast)
|
||||
{
|
||||
if (user.getUsername().equals(usernameBot))
|
||||
{
|
||||
mentionedBot = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mentionedBot || channelName.contains("general-autism")) {
|
||||
try {
|
||||
String ResponseStr;
|
||||
ResponseStr = MessageResponseHandler.selectReponseMessage(content, username);
|
||||
if (!ResponseStr.isEmpty()) {
|
||||
System.out.print("\nResponseStr3: " + ResponseStr + "\n");
|
||||
event.getMessage().getChannel().block().createMessage(ResponseStr).block();
|
||||
}
|
||||
} catch (CustomError ex) {
|
||||
Logger.getLogger(DoStuff.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Datahandler.instance.checkIfUpdateStrings();
|
||||
} catch (CustomError ex) {
|
||||
Logger.getLogger(DiscordHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}).start();
|
||||
occupied = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
import PresentationLayer.DiscordHandler;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.TextChannel;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DoStuff {
|
||||
|
||||
public static boolean occupied = false;
|
||||
|
||||
public static boolean isOccupied() {
|
||||
return occupied;
|
||||
}
|
||||
|
||||
public static void doStuff(MessageCreateEvent event, String usernameBot) {
|
||||
String username = null;
|
||||
try {
|
||||
username = event.getMessage().getAuthor().get().getUsername();
|
||||
} catch (java.util.NoSuchElementException e) {
|
||||
username = null;
|
||||
}
|
||||
if (username != null && !username.equals(usernameBot)) {
|
||||
occupied = true;
|
||||
TextChannel block = event.getMessage().getChannel().cast(TextChannel.class).block();
|
||||
String name = block.getCategory().block().getName();
|
||||
name = name.toLowerCase();
|
||||
String channelName = block.getName().toLowerCase();
|
||||
boolean channelpermissionsDenied = false;
|
||||
switch (name) {
|
||||
case "public area": {
|
||||
break;
|
||||
}
|
||||
case "information area": {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
channelpermissionsDenied = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
List<User> blockLast = event.getMessage().getUserMentions().buffer().blockLast();
|
||||
String content = event.getMessage().getContent();
|
||||
if (!channelpermissionsDenied) {
|
||||
if (blockLast != null)
|
||||
{
|
||||
for (User user : blockLast) {
|
||||
content = content.replace(user.getId().asString(), "");
|
||||
}
|
||||
}
|
||||
MessageResponseHandler.getMessage(content);
|
||||
}
|
||||
boolean mentionedBot = false;
|
||||
if (blockLast != null){
|
||||
for (User user : blockLast)
|
||||
{
|
||||
if (user.getUsername().equals(usernameBot))
|
||||
{
|
||||
mentionedBot = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mentionedBot || channelName.contains("general-autism")) {
|
||||
try {
|
||||
String ResponseStr;
|
||||
ResponseStr = MessageResponseHandler.selectReponseMessage(content, username);
|
||||
if (!ResponseStr.isEmpty()) {
|
||||
System.out.print("\nResponseStr3: " + ResponseStr + "\n");
|
||||
event.getMessage().getChannel().block().createMessage(ResponseStr).block();
|
||||
}
|
||||
} catch (CustomError ex) {
|
||||
Logger.getLogger(DoStuff.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
}
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Datahandler.instance.checkIfUpdateStrings();
|
||||
} catch (CustomError ex) {
|
||||
Logger.getLogger(DiscordHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}).start();
|
||||
occupied = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class LevenshteinDistance {
|
||||
private CharSequence lhs;
|
||||
private CharSequence rhs;
|
||||
|
||||
private static int minimum(int a, int b, int c) {
|
||||
return Math.min(Math.min(a, b), c);
|
||||
}
|
||||
|
||||
public LevenshteinDistance(CharSequence lhs, CharSequence rhs) {
|
||||
this.lhs = lhs;
|
||||
this.rhs = rhs;
|
||||
}
|
||||
|
||||
public double computeLevenshteinDistance() {
|
||||
int[][] distance = new int[lhs.length() + 1][rhs.length() + 1];
|
||||
for (int i = 0; i <= lhs.length(); i++) {
|
||||
distance[i][0] = i;
|
||||
}
|
||||
for (int j = 1; j <= rhs.length(); j++) {
|
||||
distance[0][j] = j;
|
||||
}
|
||||
for (int i = 1; i <= lhs.length(); i++) {
|
||||
for (int j = 1; j <= rhs.length(); j++) {
|
||||
distance[i][j] = minimum(
|
||||
distance[i - 1][j] + 1,
|
||||
distance[i][j - 1] + 1,
|
||||
distance[i - 1][j - 1] + ((lhs.charAt(i - 1) == rhs.charAt(j - 1)) ? 0 : 1));
|
||||
}
|
||||
}
|
||||
return distance[lhs.length()][rhs.length()];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class LevenshteinDistance {
|
||||
private CharSequence lhs;
|
||||
private CharSequence rhs;
|
||||
|
||||
private static int minimum(int a, int b, int c) {
|
||||
return Math.min(Math.min(a, b), c);
|
||||
}
|
||||
|
||||
public LevenshteinDistance(CharSequence lhs, CharSequence rhs) {
|
||||
this.lhs = lhs;
|
||||
this.rhs = rhs;
|
||||
}
|
||||
|
||||
public double computeLevenshteinDistance() {
|
||||
int[][] distance = new int[lhs.length() + 1][rhs.length() + 1];
|
||||
for (int i = 0; i <= lhs.length(); i++) {
|
||||
distance[i][0] = i;
|
||||
}
|
||||
for (int j = 1; j <= rhs.length(); j++) {
|
||||
distance[0][j] = j;
|
||||
}
|
||||
for (int i = 1; i <= lhs.length(); i++) {
|
||||
for (int j = 1; j <= rhs.length(); j++) {
|
||||
distance[i][j] = minimum(
|
||||
distance[i - 1][j] + 1,
|
||||
distance[i][j - 1] + 1,
|
||||
distance[i - 1][j - 1] + ((lhs.charAt(i - 1) == rhs.charAt(j - 1)) ? 0 : 1));
|
||||
}
|
||||
}
|
||||
return distance[lhs.length()][rhs.length()];
|
||||
}
|
||||
}
|
||||
|
@ -1,101 +1,101 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import edu.stanford.nlp.pipeline.CoreDocument;
|
||||
import edu.stanford.nlp.pipeline.CoreEntityMention;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class MessageResponseHandler {
|
||||
|
||||
private static ConcurrentMap<Integer, String> str = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
|
||||
public static ConcurrentMap<Integer, String> getStr() {
|
||||
return str;
|
||||
}
|
||||
|
||||
public static void setStr(ConcurrentMap<Integer, String> str) {
|
||||
MessageResponseHandler.str = str;
|
||||
}
|
||||
|
||||
public static void getMessage(String message) {
|
||||
if (message != null && !message.isEmpty()) {
|
||||
message = message.replace("@", "");
|
||||
if (message.contains("<>")) {
|
||||
message = message.substring(message.indexOf(">"));
|
||||
}
|
||||
if (message.startsWith("[ *")) {
|
||||
message = message.substring(message.indexOf("]"));
|
||||
}
|
||||
str.put(str.size() + 1, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static String selectReponseMessage(String toString, String personName) throws CustomError {
|
||||
ConcurrentMap<Integer, String> str1 = new MapMaker().concurrencyLevel(6).makeMap();
|
||||
str1.put(str1.size() + 1, toString);
|
||||
String strreturn = "";
|
||||
for (String str : str1.values()) {
|
||||
if (!str.isEmpty()) {
|
||||
strreturn = str;
|
||||
}
|
||||
}
|
||||
String getResponseMsg = Datahandler.instance.getResponseMsg(strreturn);
|
||||
getResponseMsg = checkPersonPresentInSentence(personName, getResponseMsg, strreturn);
|
||||
return getResponseMsg;
|
||||
}
|
||||
|
||||
private static String checkPersonPresentInSentence(String personName, String responseMsg, String userLastMessage) {
|
||||
//check if userlastmsg contains person as refference
|
||||
//check if first person is author or their person of mention
|
||||
try {
|
||||
String strreturn = responseMsg;
|
||||
CoreDocument pipelineCoreDcoument = new CoreDocument(responseMsg);
|
||||
CoreDocument pipelineCoreDcoumentLastMsg = new CoreDocument(userLastMessage);
|
||||
Datahandler.getPipeline().annotate(pipelineCoreDcoument);
|
||||
Datahandler.getPipeline().annotate(pipelineCoreDcoumentLastMsg);
|
||||
String regex = "(.*?\\d){10,}";
|
||||
for (CoreEntityMention em : pipelineCoreDcoument.entityMentions()) {
|
||||
String entityType = em.entityType();
|
||||
if (entityType.equals("PERSON")) {
|
||||
String str = strreturn;
|
||||
String emText = em.text();
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(personName);
|
||||
boolean isMatched = matcher.matches();
|
||||
if (!emText.equals(personName) && !isMatched) {
|
||||
for (CoreEntityMention emLastMsg : pipelineCoreDcoumentLastMsg.entityMentions()) {
|
||||
if (!emText.equals(emLastMsg.text()) && !Character.isDigit(emLastMsg.text().trim().charAt(0))) {
|
||||
//System.out.println("emLastMsg.text(): " + emLastMsg.text());
|
||||
str = strreturn.substring(0, strreturn.indexOf(emText)) + " "
|
||||
+ emLastMsg + " " + strreturn.substring(strreturn.indexOf(emText));
|
||||
}
|
||||
}
|
||||
str += " " + personName;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("SCUFFED JAYZ: " + e.getLocalizedMessage() + "\n");
|
||||
}
|
||||
return responseMsg;
|
||||
}
|
||||
|
||||
public static int getOverHead() {
|
||||
int getResponseMsgOverHead = Datahandler.instance.getMessageOverHead();
|
||||
return getResponseMsgOverHead;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import edu.stanford.nlp.pipeline.CoreDocument;
|
||||
import edu.stanford.nlp.pipeline.CoreEntityMention;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class MessageResponseHandler {
|
||||
|
||||
private static ConcurrentMap<Integer, String> str = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
|
||||
public static ConcurrentMap<Integer, String> getStr() {
|
||||
return str;
|
||||
}
|
||||
|
||||
public static void setStr(ConcurrentMap<Integer, String> str) {
|
||||
MessageResponseHandler.str = str;
|
||||
}
|
||||
|
||||
public static void getMessage(String message) {
|
||||
if (message != null && !message.isEmpty()) {
|
||||
message = message.replace("@", "");
|
||||
if (message.contains("<>")) {
|
||||
message = message.substring(message.indexOf(">"));
|
||||
}
|
||||
if (message.startsWith("[ *")) {
|
||||
message = message.substring(message.indexOf("]"));
|
||||
}
|
||||
str.put(str.size() + 1, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static String selectReponseMessage(String toString, String personName) throws CustomError {
|
||||
ConcurrentMap<Integer, String> str1 = new MapMaker().concurrencyLevel(6).makeMap();
|
||||
str1.put(str1.size() + 1, toString);
|
||||
String strreturn = "";
|
||||
for (String str : str1.values()) {
|
||||
if (!str.isEmpty()) {
|
||||
strreturn = str;
|
||||
}
|
||||
}
|
||||
String getResponseMsg = Datahandler.instance.getResponseMsg(strreturn);
|
||||
getResponseMsg = checkPersonPresentInSentence(personName, getResponseMsg, strreturn);
|
||||
return getResponseMsg;
|
||||
}
|
||||
|
||||
private static String checkPersonPresentInSentence(String personName, String responseMsg, String userLastMessage) {
|
||||
//check if userlastmsg contains person as refference
|
||||
//check if first person is author or their person of mention
|
||||
try {
|
||||
String strreturn = responseMsg;
|
||||
CoreDocument pipelineCoreDcoument = new CoreDocument(responseMsg);
|
||||
CoreDocument pipelineCoreDcoumentLastMsg = new CoreDocument(userLastMessage);
|
||||
Datahandler.getPipeline().annotate(pipelineCoreDcoument);
|
||||
Datahandler.getPipeline().annotate(pipelineCoreDcoumentLastMsg);
|
||||
String regex = "(.*?\\d){10,}";
|
||||
for (CoreEntityMention em : pipelineCoreDcoument.entityMentions()) {
|
||||
String entityType = em.entityType();
|
||||
if (entityType.equals("PERSON")) {
|
||||
String str = strreturn;
|
||||
String emText = em.text();
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(personName);
|
||||
boolean isMatched = matcher.matches();
|
||||
if (!emText.equals(personName) && !isMatched) {
|
||||
for (CoreEntityMention emLastMsg : pipelineCoreDcoumentLastMsg.entityMentions()) {
|
||||
if (!emText.equals(emLastMsg.text()) && !Character.isDigit(emLastMsg.text().trim().charAt(0))) {
|
||||
//System.out.println("emLastMsg.text(): " + emLastMsg.text());
|
||||
str = strreturn.substring(0, strreturn.indexOf(emText)) + " "
|
||||
+ emLastMsg + " " + strreturn.substring(strreturn.indexOf(emText));
|
||||
}
|
||||
}
|
||||
str += " " + personName;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("SCUFFED JAYZ: " + e.getLocalizedMessage() + "\n");
|
||||
}
|
||||
return responseMsg;
|
||||
}
|
||||
|
||||
public static int getOverHead() {
|
||||
int getResponseMsgOverHead = Datahandler.instance.getMessageOverHead();
|
||||
return getResponseMsgOverHead;
|
||||
}
|
||||
}
|
||||
|
@ -1,150 +1,150 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import edu.mit.jmwe.data.IMWE;
|
||||
import edu.mit.jmwe.data.IToken;
|
||||
import edu.mit.jmwe.data.Token;
|
||||
import edu.mit.jmwe.detect.CompositeDetector;
|
||||
import edu.mit.jmwe.detect.Consecutive;
|
||||
import edu.mit.jmwe.detect.Exhaustive;
|
||||
import edu.mit.jmwe.detect.IMWEDetector;
|
||||
import edu.mit.jmwe.detect.InflectionPattern;
|
||||
import edu.mit.jmwe.detect.MoreFrequentAsMWE;
|
||||
import edu.mit.jmwe.detect.ProperNouns;
|
||||
import edu.mit.jmwe.index.IMWEIndex;
|
||||
import edu.mit.jmwe.index.MWEIndex;
|
||||
import edu.stanford.nlp.ling.CoreAnnotations;
|
||||
import edu.stanford.nlp.ling.CoreLabel;
|
||||
import edu.stanford.nlp.ling.JMWEAnnotation;
|
||||
import edu.stanford.nlp.pipeline.Annotation;
|
||||
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
||||
import edu.stanford.nlp.util.CoreMap;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
//maybe not public?
|
||||
public class PipelineJMWESingleton {
|
||||
|
||||
//if not needed to be volatile dont make it, increases time
|
||||
public volatile static PipelineJMWESingleton INSTANCE;
|
||||
private static StanfordCoreNLP localNLP = initializeJMWE();
|
||||
private static String underscoreSpaceReplacement;
|
||||
|
||||
private PipelineJMWESingleton() {
|
||||
}
|
||||
|
||||
public static void getINSTANCE() {
|
||||
INSTANCE = new PipelineJMWESingleton();
|
||||
}
|
||||
|
||||
public final ConcurrentMap<String, Annotation> getJMWEAnnotation(Collection<String> strvalues) {
|
||||
boolean verbose = false;
|
||||
IMWEIndex index;
|
||||
String jmweIndexData = "/home/javatests/lib/mweindex_wordnet3.0_semcor1.6.data"; // ./lib/mweindex_wordnet3.0_semcor1.6.data
|
||||
String jmweIndexDataLocalTest = "E:/java8/Projects/mweindex_wordnet3.0_semcor1.6.data";
|
||||
File indexFile = new File((String) jmweIndexData);
|
||||
index = new MWEIndex(indexFile);
|
||||
String detectorName = "Exhaustive";
|
||||
try {
|
||||
index.open();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("unable to open IMWEIndex index: " + e + "\n");
|
||||
}
|
||||
IMWEDetector detector = getDetector(index, detectorName);
|
||||
ConcurrentMap<String, Annotation> returnAnnotations = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
strvalues.forEach(str -> {
|
||||
Annotation annoStr = new Annotation(str);
|
||||
returnAnnotations.put(str, annoStr);
|
||||
});
|
||||
localNLP.annotate(returnAnnotations.values());
|
||||
returnAnnotations.values().parallelStream().forEach(annoStr -> {
|
||||
for (CoreMap sentence : annoStr.get(CoreAnnotations.SentencesAnnotation.class)) {
|
||||
List<IMWE<IToken>> mwes = getjMWEInSentence(sentence, index, detector, verbose);
|
||||
sentence.set(JMWEAnnotation.class, mwes);
|
||||
}
|
||||
});
|
||||
index.close();
|
||||
return returnAnnotations;
|
||||
}
|
||||
|
||||
public final static StanfordCoreNLP initializeJMWE() {
|
||||
Properties propsJMWE;
|
||||
propsJMWE = new Properties();
|
||||
propsJMWE.setProperty("annotators", "tokenize,ssplit,pos,lemma");
|
||||
propsJMWE.setProperty("tokenize.options", "untokenizable=firstDelete");
|
||||
propsJMWE.setProperty("threads", "25");
|
||||
propsJMWE.setProperty("pos.maxlen", "90");
|
||||
propsJMWE.setProperty("tokenize.maxlen", "90");
|
||||
propsJMWE.setProperty("ssplit.maxlen", "90");
|
||||
propsJMWE.setProperty("lemma.maxlen", "90");
|
||||
underscoreSpaceReplacement = "-";
|
||||
localNLP = new StanfordCoreNLP(propsJMWE);
|
||||
System.out.println("finished singleton constructor \n");
|
||||
return localNLP;
|
||||
}
|
||||
|
||||
public IMWEDetector getDetector(IMWEIndex index, String detector) {
|
||||
IMWEDetector iMWEdetector = null;
|
||||
switch (detector) {
|
||||
case "Consecutive":
|
||||
iMWEdetector = new Consecutive(index);
|
||||
break;
|
||||
case "Exhaustive":
|
||||
iMWEdetector = new Exhaustive(index);
|
||||
break;
|
||||
case "ProperNouns":
|
||||
iMWEdetector = ProperNouns.getInstance();
|
||||
break;
|
||||
case "Complex":
|
||||
iMWEdetector = new CompositeDetector(ProperNouns.getInstance(),
|
||||
new MoreFrequentAsMWE(new InflectionPattern(new Consecutive(index))));
|
||||
break;
|
||||
case "CompositeConsecutiveProperNouns":
|
||||
iMWEdetector = new CompositeDetector(new Consecutive(index), ProperNouns.getInstance());
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid detector argument " + detector
|
||||
+ ", only \"Consecutive\", \"Exhaustive\", \"ProperNouns\", \"Complex\" or \"CompositeConsecutiveProperNouns\" are supported.");
|
||||
}
|
||||
return iMWEdetector;
|
||||
}
|
||||
|
||||
public List<IMWE<IToken>> getjMWEInSentence(CoreMap sentence, IMWEIndex index, IMWEDetector detector,
|
||||
boolean verbose) {
|
||||
List<IToken> tokens = getITokens(sentence.get(CoreAnnotations.TokensAnnotation.class));
|
||||
List<IMWE<IToken>> mwes = detector.detect(tokens);
|
||||
if (verbose) {
|
||||
for (IMWE<IToken> token : mwes) {
|
||||
System.out.println("IMWE<IToken>: " + token);
|
||||
}
|
||||
}
|
||||
return mwes;
|
||||
}
|
||||
|
||||
public List<IToken> getITokens(List<CoreLabel> tokens) {
|
||||
return getITokens(tokens, underscoreSpaceReplacement);
|
||||
}
|
||||
|
||||
public List<IToken> getITokens(List<CoreLabel> tokens, String underscoreSpaceReplacement) {
|
||||
List<IToken> sentence = new ArrayList<IToken>();
|
||||
for (CoreLabel token : tokens) {
|
||||
sentence.add(new Token(token.originalText().replaceAll("_", underscoreSpaceReplacement).replaceAll(" ", underscoreSpaceReplacement), token.get(CoreAnnotations.PartOfSpeechAnnotation.class), token.lemma().replaceAll("_", underscoreSpaceReplacement).replaceAll(" ", underscoreSpaceReplacement)));
|
||||
}
|
||||
return sentence;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import edu.mit.jmwe.data.IMWE;
|
||||
import edu.mit.jmwe.data.IToken;
|
||||
import edu.mit.jmwe.data.Token;
|
||||
import edu.mit.jmwe.detect.CompositeDetector;
|
||||
import edu.mit.jmwe.detect.Consecutive;
|
||||
import edu.mit.jmwe.detect.Exhaustive;
|
||||
import edu.mit.jmwe.detect.IMWEDetector;
|
||||
import edu.mit.jmwe.detect.InflectionPattern;
|
||||
import edu.mit.jmwe.detect.MoreFrequentAsMWE;
|
||||
import edu.mit.jmwe.detect.ProperNouns;
|
||||
import edu.mit.jmwe.index.IMWEIndex;
|
||||
import edu.mit.jmwe.index.MWEIndex;
|
||||
import edu.stanford.nlp.ling.CoreAnnotations;
|
||||
import edu.stanford.nlp.ling.CoreLabel;
|
||||
import edu.stanford.nlp.ling.JMWEAnnotation;
|
||||
import edu.stanford.nlp.pipeline.Annotation;
|
||||
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
|
||||
import edu.stanford.nlp.util.CoreMap;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
//maybe not public?
|
||||
public class PipelineJMWESingleton {
|
||||
|
||||
//if not needed to be volatile dont make it, increases time
|
||||
public volatile static PipelineJMWESingleton INSTANCE;
|
||||
private static StanfordCoreNLP localNLP = initializeJMWE();
|
||||
private static String underscoreSpaceReplacement;
|
||||
|
||||
private PipelineJMWESingleton() {
|
||||
}
|
||||
|
||||
public static void getINSTANCE() {
|
||||
INSTANCE = new PipelineJMWESingleton();
|
||||
}
|
||||
|
||||
public final ConcurrentMap<String, Annotation> getJMWEAnnotation(Collection<String> strvalues) {
|
||||
boolean verbose = false;
|
||||
IMWEIndex index;
|
||||
String jmweIndexData = "/home/debian/autism_bot/lib/mweindex_wordnet3.0_semcor1.6.data"; // ./lib/mweindex_wordnet3.0_semcor1.6.data
|
||||
String jmweIndexDataLocalTest = "E:/java8/Projects/mweindex_wordnet3.0_semcor1.6.data";
|
||||
File indexFile = new File((String) jmweIndexData);
|
||||
index = new MWEIndex(indexFile);
|
||||
String detectorName = "Exhaustive";
|
||||
try {
|
||||
index.open();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("unable to open IMWEIndex index: " + e + "\n");
|
||||
}
|
||||
IMWEDetector detector = getDetector(index, detectorName);
|
||||
ConcurrentMap<String, Annotation> returnAnnotations = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
strvalues.forEach(str -> {
|
||||
Annotation annoStr = new Annotation(str);
|
||||
returnAnnotations.put(str, annoStr);
|
||||
});
|
||||
localNLP.annotate(returnAnnotations.values());
|
||||
returnAnnotations.values().parallelStream().forEach(annoStr -> {
|
||||
for (CoreMap sentence : annoStr.get(CoreAnnotations.SentencesAnnotation.class)) {
|
||||
List<IMWE<IToken>> mwes = getjMWEInSentence(sentence, index, detector, verbose);
|
||||
sentence.set(JMWEAnnotation.class, mwes);
|
||||
}
|
||||
});
|
||||
index.close();
|
||||
return returnAnnotations;
|
||||
}
|
||||
|
||||
public final static StanfordCoreNLP initializeJMWE() {
|
||||
Properties propsJMWE;
|
||||
propsJMWE = new Properties();
|
||||
propsJMWE.setProperty("annotators", "tokenize,ssplit,pos,lemma");
|
||||
propsJMWE.setProperty("tokenize.options", "untokenizable=firstDelete");
|
||||
propsJMWE.setProperty("threads", "25");
|
||||
propsJMWE.setProperty("pos.maxlen", "90");
|
||||
propsJMWE.setProperty("tokenize.maxlen", "90");
|
||||
propsJMWE.setProperty("ssplit.maxlen", "90");
|
||||
propsJMWE.setProperty("lemma.maxlen", "90");
|
||||
underscoreSpaceReplacement = "-";
|
||||
localNLP = new StanfordCoreNLP(propsJMWE);
|
||||
System.out.println("finished singleton constructor \n");
|
||||
return localNLP;
|
||||
}
|
||||
|
||||
public IMWEDetector getDetector(IMWEIndex index, String detector) {
|
||||
IMWEDetector iMWEdetector = null;
|
||||
switch (detector) {
|
||||
case "Consecutive":
|
||||
iMWEdetector = new Consecutive(index);
|
||||
break;
|
||||
case "Exhaustive":
|
||||
iMWEdetector = new Exhaustive(index);
|
||||
break;
|
||||
case "ProperNouns":
|
||||
iMWEdetector = ProperNouns.getInstance();
|
||||
break;
|
||||
case "Complex":
|
||||
iMWEdetector = new CompositeDetector(ProperNouns.getInstance(),
|
||||
new MoreFrequentAsMWE(new InflectionPattern(new Consecutive(index))));
|
||||
break;
|
||||
case "CompositeConsecutiveProperNouns":
|
||||
iMWEdetector = new CompositeDetector(new Consecutive(index), ProperNouns.getInstance());
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid detector argument " + detector
|
||||
+ ", only \"Consecutive\", \"Exhaustive\", \"ProperNouns\", \"Complex\" or \"CompositeConsecutiveProperNouns\" are supported.");
|
||||
}
|
||||
return iMWEdetector;
|
||||
}
|
||||
|
||||
public List<IMWE<IToken>> getjMWEInSentence(CoreMap sentence, IMWEIndex index, IMWEDetector detector,
|
||||
boolean verbose) {
|
||||
List<IToken> tokens = getITokens(sentence.get(CoreAnnotations.TokensAnnotation.class));
|
||||
List<IMWE<IToken>> mwes = detector.detect(tokens);
|
||||
if (verbose) {
|
||||
for (IMWE<IToken> token : mwes) {
|
||||
System.out.println("IMWE<IToken>: " + token);
|
||||
}
|
||||
}
|
||||
return mwes;
|
||||
}
|
||||
|
||||
public List<IToken> getITokens(List<CoreLabel> tokens) {
|
||||
return getITokens(tokens, underscoreSpaceReplacement);
|
||||
}
|
||||
|
||||
public List<IToken> getITokens(List<CoreLabel> tokens, String underscoreSpaceReplacement) {
|
||||
List<IToken> sentence = new ArrayList<IToken>();
|
||||
for (CoreLabel token : tokens) {
|
||||
sentence.add(new Token(token.originalText().replaceAll("_", underscoreSpaceReplacement).replaceAll(" ", underscoreSpaceReplacement), token.get(CoreAnnotations.PartOfSpeechAnnotation.class), token.lemma().replaceAll("_", underscoreSpaceReplacement).replaceAll(" ", underscoreSpaceReplacement)));
|
||||
}
|
||||
return sentence;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,73 +1,73 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
import FunctionLayer.StanfordParser.SentimentValueCache;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class SimilarityMatrix {
|
||||
|
||||
private String PrimaryString;
|
||||
private String SecondaryString;
|
||||
private double distance;
|
||||
private SentimentValueCache cacheValue1;
|
||||
private SentimentValueCache cacheValue2;
|
||||
|
||||
public final double getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public final void setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public SimilarityMatrix(String str1, String str2) {
|
||||
this.PrimaryString = str1;
|
||||
this.SecondaryString = str2;
|
||||
}
|
||||
|
||||
public SimilarityMatrix(String str1, String str2, double result) {
|
||||
this.PrimaryString = str1;
|
||||
this.SecondaryString = str2;
|
||||
this.distance = result;
|
||||
}
|
||||
|
||||
public final String getPrimaryString() {
|
||||
return PrimaryString;
|
||||
}
|
||||
|
||||
public final void setPrimaryString(String PrimaryString) {
|
||||
this.PrimaryString = PrimaryString;
|
||||
}
|
||||
|
||||
public final String getSecondaryString() {
|
||||
return SecondaryString;
|
||||
}
|
||||
|
||||
public final void setSecondaryString(String SecondaryString) {
|
||||
this.SecondaryString = SecondaryString;
|
||||
}
|
||||
|
||||
public final SentimentValueCache getCacheValue1() {
|
||||
return cacheValue1;
|
||||
}
|
||||
|
||||
public final void setCacheValue1(SentimentValueCache cacheValue1) {
|
||||
this.cacheValue1 = cacheValue1;
|
||||
}
|
||||
|
||||
public final SentimentValueCache getCacheValue2() {
|
||||
return cacheValue2;
|
||||
}
|
||||
|
||||
public final void setCacheValue2(SentimentValueCache cacheValue2) {
|
||||
this.cacheValue2 = cacheValue2;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer;
|
||||
|
||||
import FunctionLayer.StanfordParser.SentimentValueCache;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class SimilarityMatrix {
|
||||
|
||||
private String PrimaryString;
|
||||
private String SecondaryString;
|
||||
private double distance;
|
||||
private SentimentValueCache cacheValue1;
|
||||
private SentimentValueCache cacheValue2;
|
||||
|
||||
public final double getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public final void setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public SimilarityMatrix(String str1, String str2) {
|
||||
this.PrimaryString = str1;
|
||||
this.SecondaryString = str2;
|
||||
}
|
||||
|
||||
public SimilarityMatrix(String str1, String str2, double result) {
|
||||
this.PrimaryString = str1;
|
||||
this.SecondaryString = str2;
|
||||
this.distance = result;
|
||||
}
|
||||
|
||||
public final String getPrimaryString() {
|
||||
return PrimaryString;
|
||||
}
|
||||
|
||||
public final void setPrimaryString(String PrimaryString) {
|
||||
this.PrimaryString = PrimaryString;
|
||||
}
|
||||
|
||||
public final String getSecondaryString() {
|
||||
return SecondaryString;
|
||||
}
|
||||
|
||||
public final void setSecondaryString(String SecondaryString) {
|
||||
this.SecondaryString = SecondaryString;
|
||||
}
|
||||
|
||||
public final SentimentValueCache getCacheValue1() {
|
||||
return cacheValue1;
|
||||
}
|
||||
|
||||
public final void setCacheValue1(SentimentValueCache cacheValue1) {
|
||||
this.cacheValue1 = cacheValue1;
|
||||
}
|
||||
|
||||
public final SentimentValueCache getCacheValue2() {
|
||||
return cacheValue2;
|
||||
}
|
||||
|
||||
public final void setCacheValue2(SentimentValueCache cacheValue2) {
|
||||
this.cacheValue2 = cacheValue2;
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,334 +1,334 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer.StanfordParser;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import edu.stanford.nlp.ling.TaggedWord;
|
||||
import edu.stanford.nlp.trees.GrammaticalStructure;
|
||||
import edu.stanford.nlp.trees.Tree;
|
||||
import edu.stanford.nlp.trees.TypedDependency;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import org.ejml.simple.SimpleMatrix;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class SentimentValueCache {
|
||||
|
||||
private String sentence;
|
||||
private int counter;
|
||||
private List<List<TaggedWord>> taggedwordlist = new ArrayList();
|
||||
private final ConcurrentMap<Integer, String> tgwlistIndex = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, Tree> sentenceConstituencyParseList = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final Collection<TypedDependency> allTypedDependencies = new ArrayList();
|
||||
private final ConcurrentMap<Integer, GrammaticalStructure> gsMap = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlist = new MapMaker().concurrencyLevel(3).makeMap();
|
||||
private final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlistVector = new MapMaker().concurrencyLevel(3).makeMap();
|
||||
private final ConcurrentMap<Integer, Integer> rnnPredictClassMap = new MapMaker().concurrencyLevel(3).makeMap();
|
||||
private List classifyRaw;
|
||||
private int mainSentiment = 0;
|
||||
private int longest = 0;
|
||||
private int tokensCounter = 0;
|
||||
private int anotatorcounter = 0;
|
||||
private int inflectedCounterPositive = 0;
|
||||
private int inflectedCounterNegative = 0;
|
||||
private int MarkedContinuousCounter = 0;
|
||||
private int MarkedContiniousCounterEntries = 0;
|
||||
private int UnmarkedPatternCounter = 0;
|
||||
private int pairCounter = 0;
|
||||
private final ConcurrentMap<Integer, String> ITokenMapTag = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenStems = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenForm = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenGetEntry = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenGetiPart = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenEntryPOS = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, Integer> entryCounts = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> nerEntities1 = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> nerEntities2 = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> nerEntityTokenTags = new MapMaker().concurrencyLevel(3).makeMap();
|
||||
private final ConcurrentMap<Integer, String> stopwordTokens = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> stopWordLemma = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
|
||||
public int getPairCounter() {
|
||||
return pairCounter;
|
||||
}
|
||||
|
||||
public void setPairCounter(int pairCounter) {
|
||||
this.pairCounter = pairCounter;
|
||||
}
|
||||
|
||||
public void addStopWordLemma(String str) {
|
||||
stopWordLemma.put(stopWordLemma.size(), str);
|
||||
}
|
||||
|
||||
public void addstopwordTokens(String str) {
|
||||
stopwordTokens.put(stopwordTokens.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getStopwordTokens() {
|
||||
return stopwordTokens;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getStopWordLemma() {
|
||||
return stopWordLemma;
|
||||
}
|
||||
|
||||
public void addnerEntityTokenTags(String str) {
|
||||
nerEntityTokenTags.put(nerEntityTokenTags.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getnerEntityTokenTags() {
|
||||
return nerEntityTokenTags;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getnerEntities1() {
|
||||
return nerEntities1;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getnerEntities2() {
|
||||
return nerEntities2;
|
||||
}
|
||||
|
||||
public void addNEREntities1(String str) {
|
||||
nerEntities1.put(nerEntities1.size(), str);
|
||||
}
|
||||
|
||||
public void addNEREntities2(String str) {
|
||||
nerEntities2.put(nerEntities2.size(), str);
|
||||
}
|
||||
|
||||
public void setTaggedwords(List<List<TaggedWord>> twlist) {
|
||||
taggedwordlist = twlist;
|
||||
}
|
||||
|
||||
public List<List<TaggedWord>> getTaggedwordlist() {
|
||||
return taggedwordlist;
|
||||
}
|
||||
|
||||
public void addEntryCounts(int counts) {
|
||||
entryCounts.put(entryCounts.size(), counts);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, Integer> getEntryCounts() {
|
||||
return entryCounts;
|
||||
}
|
||||
|
||||
public void addstrTokenEntryPOS(String str) {
|
||||
strTokenEntryPOS.put(strTokenEntryPOS.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenEntryPOS() {
|
||||
return strTokenEntryPOS;
|
||||
}
|
||||
|
||||
public void addstrTokenGetiPart(String str) {
|
||||
strTokenGetiPart.put(strTokenGetiPart.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenGetiPart() {
|
||||
return strTokenGetiPart;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenGetEntry() {
|
||||
return strTokenGetEntry;
|
||||
}
|
||||
|
||||
public void addstrTokenGetEntry(String str) {
|
||||
strTokenGetEntry.put(strTokenGetEntry.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenForm() {
|
||||
return strTokenForm;
|
||||
}
|
||||
|
||||
public void addstrTokenForm(String str) {
|
||||
strTokenForm.put(strTokenForm.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenStems() {
|
||||
return strTokenStems;
|
||||
}
|
||||
|
||||
public void addstrTokenStems(String str) {
|
||||
strTokenStems.put(strTokenStems.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getITokenMapTag() {
|
||||
return ITokenMapTag;
|
||||
}
|
||||
|
||||
public void addITokenMapTag(String str) {
|
||||
ITokenMapTag.put(ITokenMapTag.size(), str);
|
||||
}
|
||||
|
||||
public int getUnmarkedPatternCounter() {
|
||||
return UnmarkedPatternCounter;
|
||||
}
|
||||
|
||||
public void setUnmarkedPatternCounter(int UnmarkedPatternCounter) {
|
||||
this.UnmarkedPatternCounter = UnmarkedPatternCounter;
|
||||
}
|
||||
|
||||
public int getMarkedContiniousCounterEntries() {
|
||||
return MarkedContiniousCounterEntries;
|
||||
}
|
||||
|
||||
public void setMarkedContiniousCounterEntries(int MarkedContiniousCounterEntries) {
|
||||
this.MarkedContiniousCounterEntries = MarkedContiniousCounterEntries;
|
||||
}
|
||||
|
||||
public int getMarkedContinuousCounter() {
|
||||
return MarkedContinuousCounter;
|
||||
}
|
||||
|
||||
public void setMarkedContinuousCounter(int MarkedContinuousCounter) {
|
||||
this.MarkedContinuousCounter = MarkedContinuousCounter;
|
||||
}
|
||||
|
||||
public int getInflectedCounterNegative() {
|
||||
return inflectedCounterNegative;
|
||||
}
|
||||
|
||||
public void setInflectedCounterNegative(int inflectedCounterNegative) {
|
||||
this.inflectedCounterNegative = inflectedCounterNegative;
|
||||
}
|
||||
|
||||
public int getInflectedCounterPositive() {
|
||||
return inflectedCounterPositive;
|
||||
}
|
||||
|
||||
public void setInflectedCounterPositive(int inflectedCounterPositive) {
|
||||
this.inflectedCounterPositive = inflectedCounterPositive;
|
||||
}
|
||||
|
||||
public int getAnotatorcounter() {
|
||||
return anotatorcounter;
|
||||
}
|
||||
|
||||
public void setAnotatorcounter(int anotatorcounter) {
|
||||
this.anotatorcounter = anotatorcounter;
|
||||
}
|
||||
|
||||
public int getTokensCounter() {
|
||||
return tokensCounter;
|
||||
}
|
||||
|
||||
public void setTokensCounter(int tokensCounter) {
|
||||
this.tokensCounter = tokensCounter;
|
||||
}
|
||||
|
||||
public int getMainSentiment() {
|
||||
return mainSentiment;
|
||||
}
|
||||
|
||||
public void setMainSentiment(int mainSentiment) {
|
||||
this.mainSentiment = mainSentiment;
|
||||
}
|
||||
|
||||
public int getLongest() {
|
||||
return longest;
|
||||
}
|
||||
|
||||
public void setLongest(int longest) {
|
||||
this.longest = longest;
|
||||
}
|
||||
|
||||
public List getClassifyRaw() {
|
||||
return classifyRaw;
|
||||
}
|
||||
|
||||
public void setClassifyRaw(List classifyRaw) {
|
||||
this.classifyRaw = classifyRaw;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, Integer> getRnnPrediectClassMap() {
|
||||
return rnnPredictClassMap;
|
||||
}
|
||||
|
||||
public void addRNNPredictClass(int rnnPrediction) {
|
||||
rnnPredictClassMap.put(rnnPredictClassMap.size(), rnnPrediction);
|
||||
}
|
||||
|
||||
public void addSimpleMatrix(SimpleMatrix SMX) {
|
||||
simpleSMXlist.put(simpleSMXlist.size(), SMX);
|
||||
}
|
||||
|
||||
public void addSimpleMatrixVector(SimpleMatrix SMX) {
|
||||
simpleSMXlistVector.put(simpleSMXlistVector.size(), SMX);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, GrammaticalStructure> getGsMap() {
|
||||
return gsMap;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, SimpleMatrix> getSimpleSMXlist() {
|
||||
return simpleSMXlist;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, SimpleMatrix> getSimpleSMXlistVector() {
|
||||
return simpleSMXlistVector;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, GrammaticalStructure> getGs() {
|
||||
return gsMap;
|
||||
}
|
||||
|
||||
public int getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
public void addGS(GrammaticalStructure gs) {
|
||||
gsMap.put(gsMap.size(), gs);
|
||||
}
|
||||
|
||||
public Collection<TypedDependency> getAllTypedDependencies() {
|
||||
return allTypedDependencies;
|
||||
}
|
||||
|
||||
public void addTypedDependencies(Collection<TypedDependency> TDPlist) {
|
||||
for (TypedDependency TDP : TDPlist) {
|
||||
allTypedDependencies.add(TDP);
|
||||
}
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, Tree> getSentenceConstituencyParseList() {
|
||||
return sentenceConstituencyParseList;
|
||||
}
|
||||
|
||||
public void addSentenceConstituencyParse(Tree tree) {
|
||||
sentenceConstituencyParseList.put(sentenceConstituencyParseList.size(), tree);
|
||||
}
|
||||
|
||||
public void setCounter(int counter) {
|
||||
counter = counter;
|
||||
}
|
||||
|
||||
public String getSentence() {
|
||||
return sentence;
|
||||
}
|
||||
|
||||
public SentimentValueCache(String str, int counter) {
|
||||
this.sentence = str;
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getTgwlistIndex() {
|
||||
return tgwlistIndex;
|
||||
}
|
||||
|
||||
public void addTgwlistIndex(String str) {
|
||||
tgwlistIndex.put(tgwlistIndex.size(), str);
|
||||
}
|
||||
|
||||
public SentimentValueCache(String str) {
|
||||
this.sentence = str;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer.StanfordParser;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import edu.stanford.nlp.ling.TaggedWord;
|
||||
import edu.stanford.nlp.trees.GrammaticalStructure;
|
||||
import edu.stanford.nlp.trees.Tree;
|
||||
import edu.stanford.nlp.trees.TypedDependency;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import org.ejml.simple.SimpleMatrix;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class SentimentValueCache {
|
||||
|
||||
private String sentence;
|
||||
private int counter;
|
||||
private List<List<TaggedWord>> taggedwordlist = new ArrayList();
|
||||
private final ConcurrentMap<Integer, String> tgwlistIndex = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, Tree> sentenceConstituencyParseList = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final Collection<TypedDependency> allTypedDependencies = new ArrayList();
|
||||
private final ConcurrentMap<Integer, GrammaticalStructure> gsMap = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlist = new MapMaker().concurrencyLevel(3).makeMap();
|
||||
private final ConcurrentMap<Integer, SimpleMatrix> simpleSMXlistVector = new MapMaker().concurrencyLevel(3).makeMap();
|
||||
private final ConcurrentMap<Integer, Integer> rnnPredictClassMap = new MapMaker().concurrencyLevel(3).makeMap();
|
||||
private List classifyRaw;
|
||||
private int mainSentiment = 0;
|
||||
private int longest = 0;
|
||||
private int tokensCounter = 0;
|
||||
private int anotatorcounter = 0;
|
||||
private int inflectedCounterPositive = 0;
|
||||
private int inflectedCounterNegative = 0;
|
||||
private int MarkedContinuousCounter = 0;
|
||||
private int MarkedContiniousCounterEntries = 0;
|
||||
private int UnmarkedPatternCounter = 0;
|
||||
private int pairCounter = 0;
|
||||
private final ConcurrentMap<Integer, String> ITokenMapTag = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenStems = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenForm = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenGetEntry = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenGetiPart = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> strTokenEntryPOS = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, Integer> entryCounts = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> nerEntities1 = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> nerEntities2 = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> nerEntityTokenTags = new MapMaker().concurrencyLevel(3).makeMap();
|
||||
private final ConcurrentMap<Integer, String> stopwordTokens = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
private final ConcurrentMap<Integer, String> stopWordLemma = new MapMaker().concurrencyLevel(2).makeMap();
|
||||
|
||||
public int getPairCounter() {
|
||||
return pairCounter;
|
||||
}
|
||||
|
||||
public void setPairCounter(int pairCounter) {
|
||||
this.pairCounter = pairCounter;
|
||||
}
|
||||
|
||||
public void addStopWordLemma(String str) {
|
||||
stopWordLemma.put(stopWordLemma.size(), str);
|
||||
}
|
||||
|
||||
public void addstopwordTokens(String str) {
|
||||
stopwordTokens.put(stopwordTokens.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getStopwordTokens() {
|
||||
return stopwordTokens;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getStopWordLemma() {
|
||||
return stopWordLemma;
|
||||
}
|
||||
|
||||
public void addnerEntityTokenTags(String str) {
|
||||
nerEntityTokenTags.put(nerEntityTokenTags.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getnerEntityTokenTags() {
|
||||
return nerEntityTokenTags;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getnerEntities1() {
|
||||
return nerEntities1;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getnerEntities2() {
|
||||
return nerEntities2;
|
||||
}
|
||||
|
||||
public void addNEREntities1(String str) {
|
||||
nerEntities1.put(nerEntities1.size(), str);
|
||||
}
|
||||
|
||||
public void addNEREntities2(String str) {
|
||||
nerEntities2.put(nerEntities2.size(), str);
|
||||
}
|
||||
|
||||
public void setTaggedwords(List<List<TaggedWord>> twlist) {
|
||||
taggedwordlist = twlist;
|
||||
}
|
||||
|
||||
public List<List<TaggedWord>> getTaggedwordlist() {
|
||||
return taggedwordlist;
|
||||
}
|
||||
|
||||
public void addEntryCounts(int counts) {
|
||||
entryCounts.put(entryCounts.size(), counts);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, Integer> getEntryCounts() {
|
||||
return entryCounts;
|
||||
}
|
||||
|
||||
public void addstrTokenEntryPOS(String str) {
|
||||
strTokenEntryPOS.put(strTokenEntryPOS.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenEntryPOS() {
|
||||
return strTokenEntryPOS;
|
||||
}
|
||||
|
||||
public void addstrTokenGetiPart(String str) {
|
||||
strTokenGetiPart.put(strTokenGetiPart.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenGetiPart() {
|
||||
return strTokenGetiPart;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenGetEntry() {
|
||||
return strTokenGetEntry;
|
||||
}
|
||||
|
||||
public void addstrTokenGetEntry(String str) {
|
||||
strTokenGetEntry.put(strTokenGetEntry.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenForm() {
|
||||
return strTokenForm;
|
||||
}
|
||||
|
||||
public void addstrTokenForm(String str) {
|
||||
strTokenForm.put(strTokenForm.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getstrTokenStems() {
|
||||
return strTokenStems;
|
||||
}
|
||||
|
||||
public void addstrTokenStems(String str) {
|
||||
strTokenStems.put(strTokenStems.size(), str);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getITokenMapTag() {
|
||||
return ITokenMapTag;
|
||||
}
|
||||
|
||||
public void addITokenMapTag(String str) {
|
||||
ITokenMapTag.put(ITokenMapTag.size(), str);
|
||||
}
|
||||
|
||||
public int getUnmarkedPatternCounter() {
|
||||
return UnmarkedPatternCounter;
|
||||
}
|
||||
|
||||
public void setUnmarkedPatternCounter(int UnmarkedPatternCounter) {
|
||||
this.UnmarkedPatternCounter = UnmarkedPatternCounter;
|
||||
}
|
||||
|
||||
public int getMarkedContiniousCounterEntries() {
|
||||
return MarkedContiniousCounterEntries;
|
||||
}
|
||||
|
||||
public void setMarkedContiniousCounterEntries(int MarkedContiniousCounterEntries) {
|
||||
this.MarkedContiniousCounterEntries = MarkedContiniousCounterEntries;
|
||||
}
|
||||
|
||||
public int getMarkedContinuousCounter() {
|
||||
return MarkedContinuousCounter;
|
||||
}
|
||||
|
||||
public void setMarkedContinuousCounter(int MarkedContinuousCounter) {
|
||||
this.MarkedContinuousCounter = MarkedContinuousCounter;
|
||||
}
|
||||
|
||||
public int getInflectedCounterNegative() {
|
||||
return inflectedCounterNegative;
|
||||
}
|
||||
|
||||
public void setInflectedCounterNegative(int inflectedCounterNegative) {
|
||||
this.inflectedCounterNegative = inflectedCounterNegative;
|
||||
}
|
||||
|
||||
public int getInflectedCounterPositive() {
|
||||
return inflectedCounterPositive;
|
||||
}
|
||||
|
||||
public void setInflectedCounterPositive(int inflectedCounterPositive) {
|
||||
this.inflectedCounterPositive = inflectedCounterPositive;
|
||||
}
|
||||
|
||||
public int getAnotatorcounter() {
|
||||
return anotatorcounter;
|
||||
}
|
||||
|
||||
public void setAnotatorcounter(int anotatorcounter) {
|
||||
this.anotatorcounter = anotatorcounter;
|
||||
}
|
||||
|
||||
public int getTokensCounter() {
|
||||
return tokensCounter;
|
||||
}
|
||||
|
||||
public void setTokensCounter(int tokensCounter) {
|
||||
this.tokensCounter = tokensCounter;
|
||||
}
|
||||
|
||||
public int getMainSentiment() {
|
||||
return mainSentiment;
|
||||
}
|
||||
|
||||
public void setMainSentiment(int mainSentiment) {
|
||||
this.mainSentiment = mainSentiment;
|
||||
}
|
||||
|
||||
public int getLongest() {
|
||||
return longest;
|
||||
}
|
||||
|
||||
public void setLongest(int longest) {
|
||||
this.longest = longest;
|
||||
}
|
||||
|
||||
public List getClassifyRaw() {
|
||||
return classifyRaw;
|
||||
}
|
||||
|
||||
public void setClassifyRaw(List classifyRaw) {
|
||||
this.classifyRaw = classifyRaw;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, Integer> getRnnPrediectClassMap() {
|
||||
return rnnPredictClassMap;
|
||||
}
|
||||
|
||||
public void addRNNPredictClass(int rnnPrediction) {
|
||||
rnnPredictClassMap.put(rnnPredictClassMap.size(), rnnPrediction);
|
||||
}
|
||||
|
||||
public void addSimpleMatrix(SimpleMatrix SMX) {
|
||||
simpleSMXlist.put(simpleSMXlist.size(), SMX);
|
||||
}
|
||||
|
||||
public void addSimpleMatrixVector(SimpleMatrix SMX) {
|
||||
simpleSMXlistVector.put(simpleSMXlistVector.size(), SMX);
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, GrammaticalStructure> getGsMap() {
|
||||
return gsMap;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, SimpleMatrix> getSimpleSMXlist() {
|
||||
return simpleSMXlist;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, SimpleMatrix> getSimpleSMXlistVector() {
|
||||
return simpleSMXlistVector;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, GrammaticalStructure> getGs() {
|
||||
return gsMap;
|
||||
}
|
||||
|
||||
public int getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
public void addGS(GrammaticalStructure gs) {
|
||||
gsMap.put(gsMap.size(), gs);
|
||||
}
|
||||
|
||||
public Collection<TypedDependency> getAllTypedDependencies() {
|
||||
return allTypedDependencies;
|
||||
}
|
||||
|
||||
public void addTypedDependencies(Collection<TypedDependency> TDPlist) {
|
||||
for (TypedDependency TDP : TDPlist) {
|
||||
allTypedDependencies.add(TDP);
|
||||
}
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, Tree> getSentenceConstituencyParseList() {
|
||||
return sentenceConstituencyParseList;
|
||||
}
|
||||
|
||||
public void addSentenceConstituencyParse(Tree tree) {
|
||||
sentenceConstituencyParseList.put(sentenceConstituencyParseList.size(), tree);
|
||||
}
|
||||
|
||||
public void setCounter(int counter) {
|
||||
counter = counter;
|
||||
}
|
||||
|
||||
public String getSentence() {
|
||||
return sentence;
|
||||
}
|
||||
|
||||
public SentimentValueCache(String str, int counter) {
|
||||
this.sentence = str;
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
public ConcurrentMap<Integer, String> getTgwlistIndex() {
|
||||
return tgwlistIndex;
|
||||
}
|
||||
|
||||
public void addTgwlistIndex(String str) {
|
||||
tgwlistIndex.put(tgwlistIndex.size(), str);
|
||||
}
|
||||
|
||||
public SentimentValueCache(String str) {
|
||||
this.sentence = str;
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +1,71 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
|
||||
ps ax | grep EventNotfierDiscordBot-1.0
|
||||
kill $pid (number)
|
||||
|
||||
nohup screen -d -m -S nonroot java -Xmx6048M -jar /home/javatests/ArtificialAutism-1.0.jar
|
||||
nohup screen -d -m -S nonroot java -Xmx6800M -jar /home/javatests/ArtificialAutism-1.0.jar
|
||||
|
||||
screen -ls (number1)
|
||||
screen -X -S (number1) quit
|
||||
*/
|
||||
package PresentationLayer;
|
||||
|
||||
import FunctionLayer.Datahandler;
|
||||
import FunctionLayer.DoStuff;
|
||||
import FunctionLayer.PipelineJMWESingleton;
|
||||
import discord4j.core.DiscordClient;
|
||||
import discord4j.core.GatewayDiscordClient;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import DataLayer.settings;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import java.math.BigInteger;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DiscordHandler {
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "15");
|
||||
try {
|
||||
Datahandler.instance.initiateMYSQL();
|
||||
//nohup screen -d -m -S nonroot java -Xmx6900M -jar /home/javatests/ArtificialAutism-1.0.jar
|
||||
//uncomment db fetch when ready, just keep the comment for future reference
|
||||
System.out.println("finished initiating MYSQL");
|
||||
} catch (SQLException | IOException ex) {
|
||||
Logger.getLogger(DiscordHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
PipelineJMWESingleton.getINSTANCE();
|
||||
Datahandler.instance.instantiateAnnotationMapJMWE();
|
||||
Datahandler.instance.shiftReduceParserInitiate();
|
||||
Datahandler.instance.instantiateAnnotationMap();
|
||||
System.out.println("FINISHED ALL ANNOTATIONS");
|
||||
Datahandler.instance.addHLstatsMessages();
|
||||
Datahandler.instance.updateStringCache();
|
||||
//String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
||||
String token = new settings().getDiscordToken();
|
||||
final DiscordClient client = DiscordClient.create(token);
|
||||
final GatewayDiscordClient gateway = client.login().block();
|
||||
String usernameBot = gateway.getSelf().block().getUsername();
|
||||
new Thread(() -> {
|
||||
Datahandler.instance.update_autismo_socket_msg();
|
||||
}).start();
|
||||
gateway.on(MessageCreateEvent.class).subscribe(event -> {
|
||||
if (!FunctionLayer.DoStuff.isOccupied()) {
|
||||
FunctionLayer.DoStuff.doStuff(event, usernameBot);
|
||||
}
|
||||
});
|
||||
gateway.onDisconnect().block();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
|
||||
ps ax | grep EventNotfierDiscordBot-1.0
|
||||
kill $pid (number)
|
||||
|
||||
nohup screen -d -m -S nonroot java -Xmx6048M -jar /home/javatests/ArtificialAutism-1.0.jar
|
||||
nohup screen -d -m -S nonroot java -Xmx6800M -jar /home/javatests/ArtificialAutism-1.0.jar
|
||||
|
||||
screen -ls (number1)
|
||||
screen -X -S (number1) quit
|
||||
*/
|
||||
package PresentationLayer;
|
||||
|
||||
import FunctionLayer.Datahandler;
|
||||
import FunctionLayer.DoStuff;
|
||||
import FunctionLayer.PipelineJMWESingleton;
|
||||
import discord4j.core.DiscordClient;
|
||||
import discord4j.core.GatewayDiscordClient;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import DataLayer.settings;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import java.math.BigInteger;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DiscordHandler {
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "15");
|
||||
try {
|
||||
Datahandler.instance.initiateMYSQL();
|
||||
//nohup screen -d -m -S nonroot java -Xmx6900M -jar /home/javatests/ArtificialAutism-1.0.jar
|
||||
//uncomment db fetch when ready, just keep the comment for future reference
|
||||
System.out.println("finished initiating MYSQL");
|
||||
} catch (SQLException | IOException ex) {
|
||||
Logger.getLogger(DiscordHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
PipelineJMWESingleton.getINSTANCE();
|
||||
Datahandler.instance.instantiateAnnotationMapJMWE();
|
||||
Datahandler.instance.shiftReduceParserInitiate();
|
||||
Datahandler.instance.instantiateAnnotationMap();
|
||||
System.out.println("FINISHED ALL ANNOTATIONS");
|
||||
Datahandler.instance.addHLstatsMessages();
|
||||
Datahandler.instance.updateStringCache();
|
||||
//String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
||||
String token = new settings().getDiscordToken();
|
||||
final DiscordClient client = DiscordClient.create(token);
|
||||
final GatewayDiscordClient gateway = client.login().block();
|
||||
String usernameBot = gateway.getSelf().block().getUsername();
|
||||
new Thread(() -> {
|
||||
Datahandler.instance.update_autismo_socket_msg();
|
||||
}).start();
|
||||
gateway.on(MessageCreateEvent.class).subscribe(event -> {
|
||||
if (!FunctionLayer.DoStuff.isOccupied()) {
|
||||
FunctionLayer.DoStuff.doStuff(event, usernameBot);
|
||||
}
|
||||
});
|
||||
gateway.onDisconnect().block();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user