Search in sources :

Example 1 with OntClass

use of org.apache.jena.ontology.OntClass in project answer-ontology-construction by YueHub.

the class MovieConstructionServiceImpl method dealMoiveType.

public boolean dealMoiveType(Individual movieIndividual, BaikePage baikePage) {
    int index = 0;
    List<String> movieTypeList = new ArrayList<String>();
    for (String parameterName : baikePage.getParameterNames()) {
        if (parameterName.equals("类型")) {
            movieTypeList = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
            for (String movieType : movieTypeList) {
                OntClass movieTypeClass = constructionDAO.getOntClass(movieType);
                // 如果本体中此时没有该二级类
                if (movieTypeClass == null) {
                    movieTypeClass = constructionDAO.createOntClass(movieType);
                }
                // 获取一级类 电影类
                OntClass movieClass = constructionDAO.getOntClass(OntologyClassEnum.MOVIE.getName());
                // 创建子类(二级类)
                constructionDAO.addSubClass(movieClass, movieTypeClass);
                constructionDAO.addSubClass(movieIndividual, movieTypeClass);
            }
        }
        ++index;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) OntClass(org.apache.jena.ontology.OntClass)

Example 2 with OntClass

use of org.apache.jena.ontology.OntClass in project answer-ontology-construction by YueHub.

the class OthersConstructionServiceImpl 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 othersIndividual = 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("无")) {
            othersIndividual = 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);
            }
            // 获取该实体
            othersIndividual = constructionDAO.getIndividual(dictIndividualUUID);
        }
    }
    // 如果词典中不存在该实体,则插入词典并且创建一个实体
    if (othersIndividual == 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 othersClass = constructionDAO.getOntClass(parentClass.getName());
        othersIndividual = constructionDAO.createIndividual(movieIndividualUUID, othersClass);
    }
    // 创建comment
    constructionDAO.addComment(othersIndividual, individualName);
    return othersIndividual;
}
Also used : Individual(org.apache.jena.ontology.Individual) OntClass(org.apache.jena.ontology.OntClass)

Example 3 with OntClass

use of org.apache.jena.ontology.OntClass 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;
}
Also used : Individual(org.apache.jena.ontology.Individual) OntClass(org.apache.jena.ontology.OntClass)

Example 4 with OntClass

use of org.apache.jena.ontology.OntClass 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;
}
Also used : Individual(org.apache.jena.ontology.Individual) OntClass(org.apache.jena.ontology.OntClass)

Example 5 with OntClass

use of org.apache.jena.ontology.OntClass 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;
}
Also used : Individual(org.apache.jena.ontology.Individual) OntClass(org.apache.jena.ontology.OntClass)

Aggregations

OntClass (org.apache.jena.ontology.OntClass)26 Individual (org.apache.jena.ontology.Individual)16 ArrayList (java.util.ArrayList)5 Literal (org.apache.jena.rdf.model.Literal)4 OntResource (org.apache.jena.ontology.OntResource)3 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 ThreadInfo (java.lang.management.ThreadInfo)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 ExecutorService (java.util.concurrent.ExecutorService)1 OntModel (org.apache.jena.ontology.OntModel)1 InfModel (org.apache.jena.rdf.model.InfModel)1 Model (org.apache.jena.rdf.model.Model)1 Resource (org.apache.jena.rdf.model.Resource)1 StmtIterator (org.apache.jena.rdf.model.StmtIterator)1 JenaException (org.apache.jena.shared.JenaException)1 ExtendedIterator (org.apache.jena.util.iterator.ExtendedIterator)1