Search in sources :

Example 51 with Individual

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

the class CharacterConstructionServiceImpl method dealGraduateSchools.

/**
 * TODO 处理毕业院校
 * @param characterIndividual
 * @param dictIndividualList
 * @param baikePage
 * @return
 */
public boolean dealGraduateSchools(Individual characterIndividual, BaikePage baikePage) {
    List<String> graduateSchools = new ArrayList<String>();
    int index = 0;
    for (String parameterName : baikePage.getParameterNames()) {
        if (parameterName.equals("毕业院校")) {
            graduateSchools = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
            for (String graduateSchool : graduateSchools) {
                String url = null;
                int i = 0;
                for (String parameterHasUrlValue : baikePage.getParameterHasUrlValues()) {
                    if (graduateSchool.equals(parameterHasUrlValue)) {
                        url = baikePage.getParameterHasUrl().get(i);
                    }
                    ++i;
                }
                if (url != null) {
                    String polysemantExplain = "待更新";
                    Individual academyIndividual = this.queryIndividual(graduateSchool, polysemantExplain, url, true, OntologyClassEnum.ACADEMY);
                    constructionDAO.addObjectProperty(academyIndividual, "学生", characterIndividual);
                    constructionDAO.addObjectProperty(characterIndividual, "毕业于", academyIndividual);
                }
            }
        }
        ++index;
    }
    return false;
}
Also used : Individual(org.apache.jena.ontology.Individual) ArrayList(java.util.ArrayList)

Example 52 with Individual

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

the class CharacterConstructionServiceImpl method dealCompanys.

/**
 * 处理经纪公司
 * @param characterIndividual
 * @param dictIndividualList
 * @param baikePage
 * @return
 */
public boolean dealCompanys(Individual characterIndividual, BaikePage baikePage) {
    List<String> companys = new ArrayList<String>();
    int index = 0;
    for (String parameterName : baikePage.getParameterNames()) {
        if (parameterName.equals("经纪公司")) {
            companys = StringFilter.parameterValueSeparates(baikePage.getParameterValues().get(index));
            for (String company : companys) {
                String url = null;
                int i = 0;
                for (String parameterHasUrlValue : baikePage.getParameterHasUrlValues()) {
                    if (company.equals(parameterHasUrlValue)) {
                        url = baikePage.getParameterHasUrl().get(i);
                    }
                    ++i;
                }
                if (url != null) {
                    String polysemantExplain = "待更新";
                    Individual companyIndividual = this.queryIndividual(company, polysemantExplain, url, true, OntologyClassEnum.COMPANY);
                    constructionDAO.addObjectProperty(characterIndividual, "经纪公司", companyIndividual);
                }
            }
        }
        ++index;
    }
    return true;
}
Also used : Individual(org.apache.jena.ontology.Individual) ArrayList(java.util.ArrayList)

Example 53 with Individual

use of org.apache.jena.ontology.Individual in project incubator-sdap-mudrod by apache.

the class LocalOntology method synonyms.

/**
 * Retreives synonyms for an given phrase if the phrase
 * is present in the ontology
 * @param queryKeyPhrase an input string representing a phrase
 * for which we wish to obtain synonyms.
 * @return an {@link java.util.Iterator} containing synonyms string tokens
 * or an empty if no synonyms exist for the given queryKeyPhrase.
 */
@Override
public Iterator synonyms(String queryKeyPhrase) {
    Map<?, ?> classMap = retrieve(queryKeyPhrase);
    Map<Object, Object> synonyms = new HashMap<>();
    Iterator<?> iter = classMap.keySet().iterator();
    while (iter.hasNext()) {
        OntResource resource = (OntResource) iter.next();
        // listLabels
        for (Iterator<?> i = resource.listLabels(null); i.hasNext(); ) {
            Literal l = (Literal) i.next();
            synonyms.put(l.toString(), "1");
        }
        if (resource instanceof Individual) {
            // get all individuals same as this one
            for (Iterator<?> i = resource.listSameAs(); i.hasNext(); ) {
                Individual individual = (Individual) i.next();
                // add labels
                for (Iterator<?> j = individual.listLabels(null); j.hasNext(); ) {
                    Literal l = (Literal) i.next();
                    synonyms.put(l.toString(), "1");
                }
            }
        } else if (resource instanceof OntClass) {
            // list equivalent classes
            for (Iterator<?> i = ((OntClass) resource).listEquivalentClasses(); i.hasNext(); ) {
                OntClass equivClass = (OntClass) i.next();
                // add labels
                for (Iterator<?> j = equivClass.listLabels(null); j.hasNext(); ) {
                    Literal l = (Literal) j.next();
                    synonyms.put(l.toString(), "1");
                }
            }
        }
    }
    return synonyms.keySet().iterator();
}
Also used : HashMap(java.util.HashMap) Individual(org.apache.jena.ontology.Individual) Literal(org.apache.jena.rdf.model.Literal) Iterator(java.util.Iterator) OntResource(org.apache.jena.ontology.OntResource) OntClass(org.apache.jena.ontology.OntClass)

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