use of com.kyj.fx.voeditor.visual.framework.KeyValue in project Gargoyle by callakrsos.
the class ValueUtil method toTF_IDF.
public static List<KeyValue> toTF_IDF(String[] contents, boolean autoFilter) {
TF_IDF tf_IDF = new TF_IDF(contents);
String[] words = tf_IDF.getWordVector();
// 배열구조 docIndx - worIdx
double[][] tf_IDFMatrix = tf_IDF.getTF_IDFMatrix();
List<KeyValue> arrayList = new ArrayList<>();
int docCount = tf_IDFMatrix.length;
int wordCount = tf_IDFMatrix[0].length;
// 평균을 위한 합.
double[] average = new double[wordCount];
for (int docIndex = 0; docIndex < tf_IDFMatrix.length; docIndex++) {
double[] wordIndexTable = tf_IDFMatrix[docIndex];
for (int wordIndex = 0; wordIndex < wordIndexTable.length; wordIndex++) {
average[wordIndex] = wordIndexTable[wordIndex] + average[wordIndex];
}
}
// 평균값 도출.
for (int i = 0; i < average.length; i++) {
String keyword = words[i];
average[i] = average[i] / docCount;
arrayList.add(new KeyValue(keyword, average[i]));
}
// 정렬. - 내림차순.
Collections.sort(arrayList, new Comparator<KeyValue>() {
@Override
public int compare(KeyValue o1, KeyValue o2) {
Double d1 = (Double) o1.getValue();
Double d2 = (Double) o2.getValue();
return ~Double.compare(d1, d2);
}
});
return arrayList;
}
use of com.kyj.fx.voeditor.visual.framework.KeyValue in project Gargoyle by callakrsos.
the class AbstractDatabaseMetaDataController method listMetadata.
/**
* @작성자 : KYJ
* @작성일 : 2016. 11. 28.
* @return
* @throws Exception
*/
private List<KeyValue> listMetadata() throws Exception {
List<KeyValue> items = new ArrayList<>();
try (Connection connection = this.parent.getConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
Method[] declaredMethods = DatabaseMetaData.class.getDeclaredMethods();
for (Method m : declaredMethods) {
Class<?> returnType = m.getReturnType();
if ((m.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC) {
if (!m.isAccessible())
m.setAccessible(true);
if (m.isAccessible()) {
if (m.getParameterCount() == 0) {
KeyValue keyValue = new KeyValue();
String methodName = m.getName();
Object value = null;
if (returnType == java.lang.String.class) {
value = m.invoke(metaData);
} else if (returnType.isAssignableFrom(java.lang.Number.class)) {
value = m.invoke(metaData);
} else if (returnType == java.lang.Boolean.class) {
value = m.invoke(metaData);
} else if (returnType == java.lang.Character.class) {
value = m.invoke(metaData);
} else if (returnType == java.util.Properties.class) {
value = m.invoke(metaData);
if (value != null)
value = value.toString();
} else if (returnType.isAssignableFrom(java.util.Collection.class)) {
value = m.invoke(metaData);
if (value != null)
value = value.toString();
} else if (returnType.isPrimitive()) {
try {
value = m.invoke(metaData);
} catch (InvocationTargetException e) {
//NotSupprted
value = "Not Supported.";
}
}
keyValue.setKey(methodName);
keyValue.setValue(value);
items.add(keyValue);
}
}
}
}
}
return items;
}
use of com.kyj.fx.voeditor.visual.framework.KeyValue in project Gargoyle by callakrsos.
the class SimpleSQLResultView method executeSQL.
public void executeSQL(Node root) {
LOGGER.debug("sql check....");
if (this.sql == null || this.sql.isEmpty()) {
return;
}
LOGGER.debug("param bind....");
/* [시작] 바인드변수 맵핑시키는 테이블 */
param.keySet().stream().forEach(key -> {
KeyValue keyValue = new KeyValue();
keyValue.setKey(key);
keyValue.setValue(param.get(key));
tbBind.getItems().add(keyValue);
});
/* [끝] 바인드변수 맵핑시키는 테이블 */
String wrapperedSQL = ConfigResourceLoader.getInstance().get(ConfigResourceLoader.SQL_LIMIT_WRAPPER);
LOGGER.debug(String.format("wrapperedSql : %s", wrapperedSQL));
param.put(ConfigResourceLoader.USER_SQL, this.sql);
String velocityToText = ValueUtil.getVelocityToText(wrapperedSQL, param);
param.remove(ConfigResourceLoader.USER_SQL);
LOGGER.debug(String.format("before velocityText %s", velocityToText));
String sql = ValueUtil.getVelocityToText(velocityToText, param);
LOGGER.debug(String.format("after velocityText %s", sql));
columns = new ArrayList<>();
try {
// Iterator<Entry<String, Object>> iterator =
// param.entrySet().iterator();
MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource(param);
// while (iterator.hasNext()) {
// Entry<String, Object> next = iterator.next();
// Object value = null;
// if (next.getValue() != null)
// value = "'".concat(next.getValue().toString()).concat("'");
// mapSqlParameterSource.addValue(next.getKey(), value);
// }
List<Map<String, Object>> select = DbUtil.select(sql, mapSqlParameterSource, (rs, row) -> {
Map<String, Object> hashMap = new HashMap<String, Object>();
final ResultSetMetaData metaData = rs.getMetaData();
final int columnCount = metaData.getColumnCount();
hashMap = new HashMap<String, Object>();
for (int c = 1; c <= columnCount; c++) {
String columnLabel = metaData.getColumnLabel(c);
if (row == 0) {
TableModelDVO tableModelDVO = new TableModelDVO();
tableModelDVO.setDatabaseColumnName(columnLabel);
String columnTypeName = metaData.getColumnTypeName(c);
if ("unknown".equals(columnTypeName)) {
LOGGER.debug("unknown type detected....");
LOGGER.debug("convert varchar type...");
LOGGER.debug("type Number : " + metaData.getColumnType(c));
// TODO 잠재적인 버그가 있을 가능성이 있을지 ???? 확신이 안섬.
columnTypeName = "varchar";
}
tableModelDVO.setDabaseTypeName(columnTypeName);
columns.add(tableModelDVO);
}
hashMap.put(columnLabel, rs.getString(c));
}
return hashMap;
});
if (select != null && !select.isEmpty()) {
clear();
createColumns(columns);
tbResult.getItems().addAll(select);
}
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
// DialogUtil.showConfirmDialog();
// 에러 다이얼로그 수정.
DialogUtil.showExceptionDailog(SharedMemory.getPrimaryStage(), e);
}
Iterator<String> iterator = param.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next();
Object value = param.get(key);
if (value == null || value.toString().isEmpty())
param.put(key, null);
else if (value instanceof List) {
List<Object> items = (List<Object>) value;
// StringBuffer sb = new StringBuffer();
// for (Object obj : items) {
// sb.append(obj).append(",");
// }
// if (items != null && !items.isEmpty()) //bug fix. sb가 빈 경우
// 에러발생.
// sb.setLength(sb.length() - 1);
param.put(key, items);
} else
param.put(key, value);
}
this.mappingedSqlKeywords.setContent(ValueUtil.getVelocityToText(this.sql, param, true));
this.sqlKeywords.setContent(this.sql);
}
use of com.kyj.fx.voeditor.visual.framework.KeyValue in project Gargoyle by callakrsos.
the class TF_IDF method getString.
public void getString(Collection<String> links) {
URLModel[] array = links.parallelStream().map(link -> {
URLModel model = URLModel.empty();
try {
ResponseHandler<URLModel> responseHandler = new ResponseHandler<URLModel>() {
@Override
public URLModel apply(InputStream is, Integer code) {
if (code == 200) {
return new URLModel(link, ValueUtil.toString(is));
}
return URLModel.empty();
}
};
if (link.startsWith("https")) {
model = RequestUtil.requestSSL(new URL(link), responseHandler);
} else {
model = RequestUtil.request(new URL(link), responseHandler);
}
} catch (Exception e) {
return URLModel.empty();
}
return model;
}).filter(v -> !v.isEmpty()).map(v -> {
String content = v.getContent();
ExtractorBase instance = ArticleExtractor.getInstance();
InputSource source = new InputSource(new StringReader(content));
source.setEncoding("UTF-8");
try {
content = ValueUtil.HTML.getNewsContent(instance, source);
v.setContent(content);
} catch (Exception e) {
v = URLModel.empty();
e.printStackTrace();
}
return v;
}).filter(v -> !v.isEmpty()).toArray(URLModel[]::new);
List<KeyValue> tf_IDF = ValueUtil.toTF_IDF(array);
tf_IDF.forEach(v -> {
System.out.println(v.toString());
});
}
Aggregations