use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class CharacterConstructionServiceImpl method queryIndividual.
/**
* 查询实体是否在词典中存在
* @param dictIndividualList
* @param individualName
* @param polysemantExplain
* @param url
* @param isAliases
* @return
*/
public Individual queryIndividual(String individualName, String polysemantExplain, String url, boolean isAliases, OntologyClassEnum parentClass) {
// 以生省内存的方式读取Answer_Dict词典
LinkedList<String> dictIndividualList = IOUtil.readLineListWithLessMemory(Config.individualDictPath);
Individual characterIndividual = 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("无")) {
characterIndividual = 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);
}
// 获取该实体
characterIndividual = constructionDAO.getIndividual(dictIndividualUUID);
}
}
// 如果词典中不存在该实体,则插入词典并且创建一个实体
if (characterIndividual == null) {
String characterIndividualUUID = UUID.randomUUID().toString().replace("-", "");
String isAliasesWrite = null;
if (isAliases == true) {
isAliasesWrite = "1";
} else {
isAliasesWrite = "0";
}
if (polysemantExplain == null) {
polysemantExplain = "无";
}
String row_add_individual = characterIndividualUUID + "_" + individualName + "_" + polysemantExplain + "_" + url.split("#")[0] + "_" + isAliasesWrite + "_" + parentClass.getIndex();
FileIOUtil.appendContent(Config.individualDictPath, row_add_individual);
// 获取拟人类型
OntClass characterClass = constructionDAO.getOntClass(parentClass.getName());
characterIndividual = constructionDAO.createIndividual(characterIndividualUUID, characterClass);
}
// 创建comment
constructionDAO.addComment(characterIndividual, individualName);
return characterIndividual;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class CharacterConstructionServiceImpl method construction.
@Override
public boolean construction(BaikePage baikePage) throws Exception {
// 词条标题(实体名)
String individualName = baikePage.getLemmaTitle();
String polysemantExplain = baikePage.getPolysemantExplain();
String url = baikePage.getUrl();
Individual characterIndividual = null;
// 查询词典中是否有该实体 有则查询返回 没有则创建返回 true表示这是本名
characterIndividual = this.queryIndividual(individualName, polysemantExplain, url, true, OntologyClassEnum.CHARACTER);
constructionDAO.addObjectProperty(characterIndividual, "是", characterIndividual);
// 添加数据属性(描述和歧义说明)
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.CHARACTER.getName());
constructionDAO.addDataProperty(characterIndividual, "picSrc", newPicName);
}
constructionDAO.addDataProperty(characterIndividual, "URL信息来源", url);
constructionDAO.addDataProperty(characterIndividual, "描述", lemmaSummary);
constructionDAO.addDataProperty(characterIndividual, "歧义说明", polysemantExplain);
/*List<String> relationNames = baikePage.getRelationNames();
List<String> relationValues = baikePage.getParameterValues();
List<String> relationUrls = baikePage.getRelationUrls();*/
if (baikePage.getRelationNames().size() != 0 && baikePage.getRelationValues().size() != 0) {
this.dealCharacterRelations(characterIndividual, baikePage);
}
// 添加基本信息
List<String> parameterNamesFilter = baikePage.getParameterNames();
List<String> parameterValuesFilter = baikePage.getParameterValues();
constructionDAO.addDataProperties(characterIndividual, parameterNamesFilter, parameterValuesFilter);
// 处理别名
this.dealAliases(characterIndividual, baikePage);
// 处理职业
this.dealProfession(characterIndividual, baikePage);
// 处理人物-地区对象(国籍对象属性) TODO 超链接情况
this.dealNationality(characterIndividual, baikePage);
// 处理人物-院校对象(毕业院校对象属性)
this.dealGraduateSchools(characterIndividual, baikePage);
// 处理人物-公司对象(毕业院校公司属性)
this.dealCompanys(characterIndividual, baikePage);
return false;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class CharacterConstructionServiceImpl method dealNationality.
/**
* TODO 处理国籍不应该直接判断为地区类处理国籍属性
* @param characterIndividual
* @param baikePage
* @return
*/
public boolean dealNationality(Individual characterIndividual, BaikePage baikePage) {
List<String> nationalities = new ArrayList<String>();
int index = 0;
for (String parameterName : baikePage.getParameterNames()) {
if (parameterName.equals("国籍")) {
nationalities = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
for (String nationality : nationalities) {
String url = null;
int i = 0;
for (String parameterHasUrlValue : baikePage.getParameterHasUrlValues()) {
if (nationality.equals(parameterHasUrlValue)) {
url = baikePage.getParameterHasUrl().get(i);
}
++i;
}
if (url != null) {
String polysemantExplain = "待更新";
Individual nationalityIndividual = this.queryIndividual(nationality, polysemantExplain, url, true, OntologyClassEnum.AREA);
constructionDAO.addObjectProperty(nationalityIndividual, "公民", characterIndividual);
}
}
}
++index;
}
return false;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class MusicConstructionServiceImpl method dealCharacters.
public boolean dealCharacters(Individual musicIndividual, BaikePage baikePage) {
List<String> characters = new ArrayList<String>();
int index = 0;
for (String parameterName : baikePage.getParameterNames()) {
if (parameterName.equals("歌曲原唱")) {
characters = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
for (String character : characters) {
String url = null;
int i = 0;
for (String parameterHasUrlValue : baikePage.getParameterHasUrlValues()) {
if (character.equals(parameterHasUrlValue)) {
url = baikePage.getParameterHasUrl().get(i);
}
++i;
}
if (url != null) {
String polysemantExplain = "待更新";
Individual characterIndividual = this.queryIndividual(character, polysemantExplain, url, true, OntologyClassEnum.CHARACTER);
constructionDAO.addObjectProperty(characterIndividual, "演唱", musicIndividual);
constructionDAO.addObjectProperty(characterIndividual, "唱", musicIndividual);
}
}
}
if (parameterName.equals("填词")) {
characters = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
for (String character : characters) {
String url = null;
int i = 0;
for (String parameterHasUrlValue : baikePage.getParameterHasUrlValues()) {
if (character.equals(parameterHasUrlValue)) {
url = baikePage.getParameterHasUrl().get(i);
}
++i;
}
if (url != null) {
String polysemantExplain = "待更新";
Individual characterIndividual = this.queryIndividual(character, polysemantExplain, url, true, OntologyClassEnum.CHARACTER);
constructionDAO.addObjectProperty(characterIndividual, "填词", musicIndividual);
constructionDAO.addObjectProperty(characterIndividual, "写", musicIndividual);
}
}
}
if (parameterName.equals("谱曲")) {
characters = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
for (String character : characters) {
String url = null;
int i = 0;
for (String parameterHasUrlValue : baikePage.getParameterHasUrlValues()) {
if (character.equals(parameterHasUrlValue)) {
url = baikePage.getParameterHasUrl().get(i);
}
++i;
}
if (url != null) {
String polysemantExplain = "待更新";
Individual characterIndividual = this.queryIndividual(character, polysemantExplain, url, true, OntologyClassEnum.CHARACTER);
constructionDAO.addObjectProperty(characterIndividual, "谱曲", musicIndividual);
constructionDAO.addObjectProperty(characterIndividual, "写", musicIndividual);
}
}
}
if (parameterName.equals("编曲")) {
characters = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
for (String character : characters) {
String url = null;
int i = 0;
for (String parameterHasUrlValue : baikePage.getParameterHasUrlValues()) {
if (character.equals(parameterHasUrlValue)) {
url = baikePage.getParameterHasUrl().get(i);
}
++i;
}
if (url != null) {
String polysemantExplain = "待更新";
Individual characterIndividual = this.queryIndividual(character, polysemantExplain, url, true, OntologyClassEnum.CHARACTER);
constructionDAO.addObjectProperty(characterIndividual, "编曲", musicIndividual);
constructionDAO.addObjectProperty(characterIndividual, "写", musicIndividual);
}
}
}
++index;
}
return true;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class MusicConstructionServiceImpl 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 musicIndividual = 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("无")) {
musicIndividual = 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);
}
// 获取该实体
musicIndividual = constructionDAO.getIndividual(dictIndividualUUID);
}
}
// 如果词典中不存在该实体,则插入词典并且创建一个实体
if (musicIndividual == 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 musicClass = constructionDAO.getOntClass(parentClass.getName());
musicIndividual = constructionDAO.createIndividual(movieIndividualUUID, musicClass);
}
// 创建comment
constructionDAO.addComment(musicIndividual, individualName);
return musicIndividual;
}
Aggregations