Search in sources :

Example 21 with Individual

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

the class MusicConstructionServiceImpl method construction.

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

Example 22 with Individual

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

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

Example 23 with Individual

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

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

Example 24 with Individual

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

the class CaricatureConstructionServiceImpl method dealAreas.

public boolean dealAreas(Individual caricatureIndividual, 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) {
                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 areaIndividual = this.queryIndividual(area, polysemantExplain, url, true, OntologyClassEnum.AREA);
                    constructionDAO.addObjectProperty(caricatureIndividual, "属于", areaIndividual);
                }
                // 创建二级类
                OntClass areaClass = constructionDAO.getOntClass(area);
                // 如果本体中此时没有该二级类
                if (areaClass == null) {
                    areaClass = constructionDAO.createOntClass(area);
                }
                // 获取一级类 动画类
                OntClass caricatureClass = constructionDAO.getOntClass(OntologyClassEnum.CARICATURE.getName());
                // 创建子类(二级类)
                constructionDAO.addSubClass(caricatureClass, areaClass);
                constructionDAO.addSubClass(caricatureIndividual, areaClass);
            }
        }
        ++index;
    }
    return false;
}
Also used : Individual(org.apache.jena.ontology.Individual) ArrayList(java.util.ArrayList) OntClass(org.apache.jena.ontology.OntClass)

Example 25 with Individual

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

the class CaricatureConstructionServiceImpl method dealCharacters.

public boolean dealCharacters(Individual caricatureIndividual, 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, "创作", caricatureIndividual);
                    constructionDAO.addObjectProperty(characterIndividual, "有漫画", caricatureIndividual);
                    constructionDAO.addObjectProperty(caricatureIndividual, "作者", characterIndividual);
                }
            }
        }
        ++index;
    }
    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