use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class AcademyConstructionServiceImpl method queryIndividual.
public Individual queryIndividual(String individualName, String polysemantExplain, String url, boolean isAliases, OntologyClassEnum parentClass) {
// 以生省内存的方式读取Answer_Dict词典
LinkedList<String> dictIndividualList = IOUtil.readLineListWithLessMemory(Config.individualDictPath);
Individual academyIndividual = null;
Long rowNum = 0l;
// 遍历词典中的实体记录 判断当前实体是否已经存在
for (String row : dictIndividualList) {
++rowNum;
String[] fieldsDict = row.split("_");
// UUID
String dictIndividualUUID = fieldsDict[0];
// 实体名
String dictIndividualName = fieldsDict[1];
// 歧义说明
String dictPolysemantExplain = fieldsDict[2];
// 实体百科页面URL
String dictIndividualURL = fieldsDict[3];
// 是否是本名
String dictIsAliasesWrite = fieldsDict[4];
// 实体所属类型
int dictIndividualClass = Integer.parseInt(fieldsDict[5]);
// 第一种情况:如果找到实体名相同并且明确指出该实体没有歧义则 该实体就是当前迭代到的实体
if (individualName.equals(dictIndividualName) && dictPolysemantExplain.equals("无")) {
academyIndividual = constructionDAO.getIndividual(dictIndividualUUID);
// 找到完全相同的实体了 使用#去除所有框架定位网页
} else if (individualName.equals(dictIndividualName) && url.split("#")[0].equals(dictIndividualURL) && dictIndividualClass == parentClass.getIndex()) {
// 如果此时抓到的实体歧义不为空 则表示该实体有同名实体 则更新词典 TODO 应该把 != null 去掉
if (dictPolysemantExplain.equals("待更新")) {
if (polysemantExplain == null) {
polysemantExplain = "无";
}
// 更新词典 修改歧义说明字段
row = dictIndividualUUID + "_" + dictIndividualName + "_" + polysemantExplain + "_" + dictIndividualURL + "_" + dictIsAliasesWrite + "_" + parentClass.getIndex();
// 更新Answer_Dict
FileIOUtil.updateContent(Config.individualDictPath, rowNum, row);
}
// 获取该实体
academyIndividual = constructionDAO.getIndividual(dictIndividualUUID);
}
}
// 如果词典中不存在该实体,则插入词典并且创建一个实体
if (academyIndividual == null) {
String movieIndividualUUID = UUID.randomUUID().toString().replace("-", "");
String isAliasesWrite = null;
if (isAliases == true) {
isAliasesWrite = "1";
} else {
isAliasesWrite = "0";
}
if (polysemantExplain == null) {
polysemantExplain = "无";
}
String row_add_individual = movieIndividualUUID + "_" + individualName + "_" + polysemantExplain + "_" + url.split("#")[0] + "_" + isAliasesWrite + "_" + parentClass.getIndex();
FileIOUtil.appendContent(Config.individualDictPath, row_add_individual);
// 获取电影类型
OntClass movieClass = constructionDAO.getOntClass(parentClass.getName());
academyIndividual = constructionDAO.createIndividual(movieIndividualUUID, movieClass);
}
// 创建comment
constructionDAO.addComment(academyIndividual, individualName);
return academyIndividual;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class AcademyConstructionServiceImpl method construction.
@Override
public boolean construction(BaikePage baikePage) throws Exception {
// 词条标题(实体名)
String individualName = baikePage.getLemmaTitle();
String polysemantExplain = baikePage.getPolysemantExplain();
String url = baikePage.getUrl();
Individual academyIndividual = null;
// 查询词典中是否有该实体 有则查询返回 没有则创建返回 true表示这是本名
academyIndividual = this.queryIndividual(individualName, polysemantExplain, url, true, OntologyClassEnum.ACADEMY);
constructionDAO.addObjectProperty(academyIndividual, "是", academyIndividual);
// 添加数据属性(描述和歧义说明)
String lemmaSummary = baikePage.getLemmaSummary();
String picSrc = baikePage.getPicSrc();
if (picSrc != null) {
// 取得当前时间
long times = System.currentTimeMillis();
// 生成0-1000的随机数
int random = (int) (Math.random() * 1000);
// 扩展名称
String newPicName = times + "" + random + ".jpg";
PictureDownloader.picDownload(picSrc, newPicName, Config.picSavePath + File.separator + OntologyClassEnum.ACADEMY.getName());
constructionDAO.addDataProperty(academyIndividual, "picSrc", newPicName);
}
constructionDAO.addDataProperty(academyIndividual, "URL信息来源", url);
constructionDAO.addDataProperty(academyIndividual, "描述", lemmaSummary);
constructionDAO.addDataProperty(academyIndividual, "歧义说明", polysemantExplain);
// 添加基本信息
List<String> parameterNamesFilter = baikePage.getParameterNames();
List<String> parameterValuesFilter = baikePage.getParameterValues();
constructionDAO.addDataProperties(academyIndividual, parameterNamesFilter, parameterValuesFilter);
return false;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class AreaConstructionServiceImpl method construction.
@Override
public boolean construction(BaikePage baikePage) throws Exception {
// 词条标题(实体名)
String individualName = baikePage.getLemmaTitle();
String polysemantExplain = baikePage.getPolysemantExplain();
String url = baikePage.getUrl();
Individual areaIndividual = null;
// 查询词典中是否有该实体 有则查询返回 没有则创建返回 true表示这是本名
areaIndividual = this.queryIndividual(individualName, polysemantExplain, url, true, OntologyClassEnum.AREA);
constructionDAO.addObjectProperty(areaIndividual, "是", areaIndividual);
// 添加数据属性(描述和歧义说明)
String lemmaSummary = baikePage.getLemmaSummary();
String picSrc = baikePage.getPicSrc();
if (picSrc != null) {
// 取得当前时间
long times = System.currentTimeMillis();
// 生成0-1000的随机数
int random = (int) (Math.random() * 1000);
// 扩展名称
String newPicName = times + "" + random + ".jpg";
PictureDownloader.picDownload(picSrc, newPicName, Config.picSavePath + File.separator + OntologyClassEnum.AREA.getName());
constructionDAO.addDataProperty(areaIndividual, "picSrc", newPicName);
}
constructionDAO.addDataProperty(areaIndividual, "URL信息来源", url);
constructionDAO.addDataProperty(areaIndividual, "描述", lemmaSummary);
constructionDAO.addDataProperty(areaIndividual, "歧义说明", polysemantExplain);
// 添加基本信息
List<String> parameterNamesFilter = baikePage.getParameterNames();
List<String> parameterValuesFilter = baikePage.getParameterValues();
constructionDAO.addDataProperties(areaIndividual, parameterNamesFilter, parameterValuesFilter);
// 处理地区-地区对象
this.dealAreas(areaIndividual, baikePage);
// 处理地区-音乐对象
this.dealMusics(areaIndividual, baikePage);
return false;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class AreaConstructionServiceImpl method queryIndividual.
public Individual queryIndividual(String individualName, String polysemantExplain, String url, boolean isAliases, OntologyClassEnum parentClass) {
// 以生省内存的方式读取Answer_Dict词典
LinkedList<String> dictIndividualList = IOUtil.readLineListWithLessMemory(Config.individualDictPath);
Individual areaIndividual = null;
Long rowNum = 0l;
// 遍历词典中的实体记录 判断当前实体是否已经存在
for (String row : dictIndividualList) {
++rowNum;
String[] fieldsDict = row.split("_");
// UUID
String dictIndividualUUID = fieldsDict[0];
// 实体名
String dictIndividualName = fieldsDict[1];
// 歧义说明
String dictPolysemantExplain = fieldsDict[2];
// 实体百科页面URL
String dictIndividualURL = fieldsDict[3];
// 是否是本名
String dictIsAliasesWrite = fieldsDict[4];
// 实体所属类型
int dictIndividualClass = Integer.parseInt(fieldsDict[5]);
// 第一种情况:如果找到实体名相同并且明确指出该实体没有歧义则 该实体就是当前迭代到的实体
if (individualName.equals(dictIndividualName) && dictPolysemantExplain.equals("无")) {
areaIndividual = constructionDAO.getIndividual(dictIndividualUUID);
// 找到完全相同的实体了 使用#去除所有框架定位网页
} else if (individualName.equals(dictIndividualName) && url.split("#")[0].equals(dictIndividualURL) && dictIndividualClass == parentClass.getIndex()) {
// 如果此时抓到的实体歧义不为空 则表示该实体有同名实体 则更新词典 TODO 应该把 != null 去掉
if (dictPolysemantExplain.equals("待更新")) {
if (polysemantExplain == null) {
polysemantExplain = "无";
}
// 更新词典 修改歧义说明字段
row = dictIndividualUUID + "_" + dictIndividualName + "_" + polysemantExplain + "_" + dictIndividualURL + "_" + dictIsAliasesWrite + "_" + parentClass.getIndex();
// 更新Answer_Dict
FileIOUtil.updateContent(Config.individualDictPath, rowNum, row);
}
// 获取该实体
areaIndividual = constructionDAO.getIndividual(dictIndividualUUID);
}
}
// 如果词典中不存在该实体,则插入词典并且创建一个实体
if (areaIndividual == null) {
String areaIndividualUUID = UUID.randomUUID().toString().replace("-", "");
String isAliasesWrite = null;
if (isAliases == true) {
isAliasesWrite = "1";
} else {
isAliasesWrite = "0";
}
if (polysemantExplain == null) {
polysemantExplain = "无";
}
String row_add_individual = areaIndividualUUID + "_" + individualName + "_" + polysemantExplain + "_" + url.split("#")[0] + "_" + isAliasesWrite + "_" + parentClass.getIndex();
FileIOUtil.appendContent(Config.individualDictPath, row_add_individual);
// 获取电影类型
OntClass areaClass = constructionDAO.getOntClass(parentClass.getName());
areaIndividual = constructionDAO.createIndividual(areaIndividualUUID, areaClass);
}
// 创建comment
constructionDAO.addComment(areaIndividual, individualName);
return areaIndividual;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class CharacterConstructionServiceImpl method dealAliases.
/**
* 处理别名(人物实体别名)
* @param characterIndividual
* @param dictIndividualList
* @param individualName
* @param polysemantExplain
* @param url
* @return
*/
public boolean dealAliases(Individual characterIndividual, BaikePage baikePage) {
// 获取实体别名
List<String> aliasList = new ArrayList<String>();
int index = 0;
for (String parameterNameFilter : baikePage.getParameterNames()) {
if (parameterNameFilter.equals("别名")) {
aliasList = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
for (String alias : aliasList) {
// false表示不是本名 而是别名(即等价类)
// 因为别名作为该百科页面实体的等价类 ,所以URL应该相同
Individual aliasIndividual = this.queryIndividual(alias, baikePage.getLemmaTitle() + "的别名", baikePage.getUrl(), false, OntologyClassEnum.CHARACTER);
// 添加等价类
constructionDAO.addSameAs(characterIndividual, aliasIndividual);
}
}
++index;
}
return true;
}
Aggregations