Search in sources :

Example 46 with Individual

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

the class CaricatureConstructionServiceImpl method construction.

@Override
public boolean construction(BaikePage baikePage) throws Exception {
    // 词条标题(实体名)
    String individualName = baikePage.getLemmaTitle();
    String polysemantExplain = baikePage.getPolysemantExplain();
    String url = baikePage.getUrl();
    Individual caricatureIndividual = null;
    // 查询词典中是否有该实体 有则查询返回 没有则创建返回  true表示这是本名
    caricatureIndividual = this.queryIndividual(individualName, polysemantExplain, url, true, OntologyClassEnum.CARICATURE);
    constructionDAO.addObjectProperty(caricatureIndividual, "是", caricatureIndividual);
    // 添加数据属性(描述和歧义说明)
    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.CARICATURE.getName());
        constructionDAO.addDataProperty(caricatureIndividual, "picSrc", newPicName);
    }
    constructionDAO.addDataProperty(caricatureIndividual, "URL信息来源", url);
    constructionDAO.addDataProperty(caricatureIndividual, "描述", lemmaSummary);
    constructionDAO.addDataProperty(caricatureIndividual, "歧义说明", polysemantExplain);
    // 添加基本信息
    List<String> parameterNamesFilter = baikePage.getParameterNames();
    List<String> parameterValuesFilter = baikePage.getParameterValues();
    constructionDAO.addDataProperties(caricatureIndividual, parameterNamesFilter, parameterValuesFilter);
    // 处理漫画-人物对象
    this.dealCharacters(caricatureIndividual, baikePage);
    // 处理动画-地区对象
    this.dealAreas(caricatureIndividual, baikePage);
    // 处理动画-公司对象
    this.dealCompanys(caricatureIndividual, baikePage);
    return true;
}
Also used : Individual(org.apache.jena.ontology.Individual)

Example 47 with Individual

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

the class CompanyConstructionServiceImpl 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 companyIndividual = 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("无")) {
            companyIndividual = 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);
            }
            // 获取该实体
            companyIndividual = constructionDAO.getIndividual(dictIndividualUUID);
        }
    }
    // 如果词典中不存在该实体,则插入词典并且创建一个实体
    if (companyIndividual == null) {
        String companyIndividualUUID = UUID.randomUUID().toString().replace("-", "");
        String isAliasesWrite = null;
        if (isAliases == true) {
            isAliasesWrite = "1";
        } else {
            isAliasesWrite = "0";
        }
        if (polysemantExplain == null) {
            polysemantExplain = "无";
        }
        String row_add_individual = companyIndividualUUID + "_" + individualName + "_" + polysemantExplain + "_" + url.split("#")[0] + "_" + isAliasesWrite + "_" + parentClass.getIndex();
        FileIOUtil.appendContent(Config.individualDictPath, row_add_individual);
        // 获取电影类型
        OntClass companyClass = constructionDAO.getOntClass(parentClass.getName());
        companyIndividual = constructionDAO.createIndividual(companyIndividualUUID, companyClass);
    }
    // 创建comment
    constructionDAO.addComment(companyIndividual, individualName);
    return companyIndividual;
}
Also used : Individual(org.apache.jena.ontology.Individual) OntClass(org.apache.jena.ontology.OntClass)

Example 48 with Individual

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

the class AreaConstructionServiceImpl method dealAreas.

public boolean dealAreas(Individual areaIndividual, BaikePage baikePage) {
    List<String> areas = new ArrayList<String>();
    int index = 0;
    for (String parameterName : baikePage.getParameterNames()) {
        if (parameterName.equals("所属州")) {
            areas = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
            for (String area : areas) {
                // 创建二级类
                OntClass stateAreaClass = constructionDAO.getOntClass(area);
                // 如果本体中此时没有该二级类
                if (stateAreaClass == null) {
                    stateAreaClass = constructionDAO.createOntClass(area);
                }
                // 获取一级类 地区类
                OntClass areaClass = constructionDAO.getOntClass(OntologyClassEnum.AREA.getName());
                // 创建子类(二级类)
                constructionDAO.addSubClass(areaClass, stateAreaClass);
                constructionDAO.addSubClass(areaIndividual, stateAreaClass);
            }
        }
        if (parameterName.equals("首都")) {
            areas = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
            for (String area : areas) {
                String url = null;
                int i = 0;
                for (String parameterHasUrlValue : baikePage.getParameterHasUrlValues()) {
                    if (area.equals(parameterHasUrlValue)) {
                        url = baikePage.getParameterHasUrl().get(i);
                    }
                    ++i;
                }
                if (url != null) {
                    String polysemantExplain = "待更新";
                    Individual capitalIndividual = this.queryIndividual(area, polysemantExplain, url, true, OntologyClassEnum.AREA);
                    constructionDAO.addObjectProperty(capitalIndividual, "属于", areaIndividual);
                    constructionDAO.addObjectProperty(areaIndividual, "首都", capitalIndividual);
                }
            }
        }
        ++index;
    }
    return false;
}
Also used : Individual(org.apache.jena.ontology.Individual) ArrayList(java.util.ArrayList) OntClass(org.apache.jena.ontology.OntClass)

Example 49 with Individual

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

the class AreaConstructionServiceImpl method dealMusics.

public boolean dealMusics(Individual areaIndividual, BaikePage baikePage) {
    List<String> musics = new ArrayList<String>();
    int index = 0;
    for (String parameterName : baikePage.getParameterNames()) {
        if (parameterName.equals("国歌")) {
            musics = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
            for (String music : musics) {
                String url = null;
                int i = 0;
                for (String parameterHasUrlValue : baikePage.getParameterHasUrlValues()) {
                    if (music.equals(parameterHasUrlValue)) {
                        url = baikePage.getParameterHasUrl().get(i);
                    }
                    ++i;
                }
                if (url != null) {
                    String polysemantExplain = "待更新";
                    Individual musicIndividual = this.queryIndividual(music, polysemantExplain, url, true, OntologyClassEnum.MUSIC);
                    constructionDAO.addObjectProperty(areaIndividual, "国歌", musicIndividual);
                }
            }
        }
        ++index;
    }
    return false;
}
Also used : Individual(org.apache.jena.ontology.Individual) ArrayList(java.util.ArrayList)

Example 50 with Individual

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

the class CharacterConstructionServiceImpl method dealCharacterRelations.

/**
 * 处理人物关系
 * @param characterIndividual
 * @param dictIndividualList
 * @param baikePage
 * @return
 */
public boolean dealCharacterRelations(Individual characterIndividual, BaikePage baikePage) {
    int index = 0;
    List<Individual> relationCharacterIndividuals = new ArrayList<Individual>();
    for (String relationValue : baikePage.getRelationValues()) {
        // 歧义理解暂时为空
        String polysemantExplain = "待更新";
        String relationUrl = baikePage.getRelationUrls().get(index);
        if (relationUrl != null) {
            // true 表示此为本名
            Individual relationCharacterIndividual = this.queryIndividual(relationValue, polysemantExplain, relationUrl, true, OntologyClassEnum.CHARACTER);
            relationCharacterIndividuals.add(relationCharacterIndividual);
        }
        ++index;
    }
    // 将人物实体关系添加到本体库中
    constructionDAO.addObjectProperties(characterIndividual, baikePage.getRelationNames(), relationCharacterIndividuals);
    List<String> newRelationNames = new ArrayList<String>();
    for (String relationName : baikePage.getRelationNames()) {
        newRelationNames.add("有" + relationName);
    }
    constructionDAO.addObjectProperties(characterIndividual, newRelationNames, relationCharacterIndividuals);
    return true;
}
Also used : Individual(org.apache.jena.ontology.Individual) ArrayList(java.util.ArrayList)

Aggregations

Individual (org.apache.jena.ontology.Individual)53 ArrayList (java.util.ArrayList)17 OntClass (org.apache.jena.ontology.OntClass)16 Literal (org.apache.jena.rdf.model.Literal)6 OntModel (org.apache.jena.ontology.OntModel)4 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 MediaType (javax.ws.rs.core.MediaType)2 ObjectProperty (org.apache.jena.ontology.ObjectProperty)2 OntResource (org.apache.jena.ontology.OntResource)2 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Model (org.apache.jena.rdf.model.Model)1 Resource (org.apache.jena.rdf.model.Resource)1 Address (org.orcid.jaxb.model.message.Address)1 Email (org.orcid.jaxb.model.message.Email)1 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)1 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1