use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.
the class RDFMessageBodyWriterV2 method writeTo.
@Override
public void writeTo(Record record, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
OntModel m = getOntModel();
// System.out.println(httpHeaders);
Individual profileDoc = null;
if (record != null) {
Individual person = describePerson(record, m);
if (person != null) {
profileDoc = describeAccount(record, m, person);
}
}
MediaType jsonLd = new MediaType("application", "ld+json");
MediaType nTriples = new MediaType("application", "n-triples");
MediaType rdfXml = new MediaType("application", "rdf+xml");
String base = null;
if (getUriInfo() != null) {
getUriInfo().getAbsolutePath().toASCIIString();
}
if (mediaType.isCompatible(nTriples)) {
// NOTE: N-Triples requires absolute URIs
m.write(entityStream, "N-TRIPLES");
} else if (mediaType.isCompatible(jsonLd)) {
m.write(entityStream, "JSON-LD", base);
} else if (mediaType.isCompatible(rdfXml)) {
m.write(entityStream, "RDF/XML", base);
} else {
// Turtle is the safest default
m.write(entityStream, "TURTLE", base);
}
}
use of org.apache.jena.ontology.Individual in project ORCID-Source by ORCID.
the class RDFMessageBodyWriterV2 method describeResearcherUrls.
private void describeResearcherUrls(org.orcid.jaxb.model.record_v2.ResearcherUrls researcherUrls, Individual person, OntModel m) {
if (researcherUrls == null || researcherUrls.getResearcherUrls() == null) {
return;
}
for (ResearcherUrl url : researcherUrls.getResearcherUrls()) {
Individual page = m.createIndividual(url.getUrl().getValue(), null);
String urlName = url.getUrlName();
if (isHomePage(urlName)) {
person.addProperty(FOAF.homepage, page);
} else if (isFoaf(urlName)) {
// TODO: What if we want to link to the URL of the other FOAF
// *Profile*?
// Note: We don't dear here to do owl:sameAs or
// prov:specializationOf as we don't know the extent of the
// other FOAF profile - we'll
// suffice to say it's an alternate view of the same person
person.addProperty(PROV.alternateOf, page);
page.addRDFType(FOAF.Person);
page.addRDFType(PROV.Person);
person.addSeeAlso(page);
} else if (isWebID(urlName)) {
person.addSameAs(page);
} else if (isInbox(urlName)) {
person.addProperty(LDP.inbox, page);
} else if (isOutbox(urlName)) {
person.addProperty(AS.outbox, page);
} else if (isStorage(urlName)) {
person.addProperty(PIM.storage, page);
} else {
// It's some other foaf:page which might not be about
// this person
person.addProperty(FOAF.page, page);
}
}
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class MovieConstructionServiceImpl method dealCharacters.
public boolean dealCharacters(Individual movieIndividual, 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, "有电影", movieIndividual);
constructionDAO.addObjectProperty(characterIndividual, "导演", movieIndividual);
constructionDAO.addObjectProperty(characterIndividual, "拍", movieIndividual);
constructionDAO.addObjectProperty(characterIndividual, "执导", movieIndividual);
constructionDAO.addObjectProperty(movieIndividual, "有导演", characterIndividual);
}
}
}
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, "有电影", movieIndividual);
constructionDAO.addObjectProperty(characterIndividual, "主演", movieIndividual);
constructionDAO.addObjectProperty(characterIndividual, "出演", movieIndividual);
constructionDAO.addObjectProperty(characterIndividual, "拍", movieIndividual);
constructionDAO.addObjectProperty(characterIndividual, "参演", movieIndividual);
constructionDAO.addObjectProperty(movieIndividual, "有主演", characterIndividual);
constructionDAO.addObjectProperty(movieIndividual, "有演员", characterIndividual);
}
}
}
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, "编写", movieIndividual);
constructionDAO.addObjectProperty(characterIndividual, "编剧", movieIndividual);
constructionDAO.addObjectProperty(movieIndividual, "有编剧", characterIndividual);
}
}
}
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, "制作", movieIndividual);
constructionDAO.addObjectProperty(movieIndividual, "有制片", characterIndividual);
constructionDAO.addObjectProperty(movieIndividual, "有制片人", characterIndividual);
}
}
}
++index;
}
return true;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class MovieConstructionServiceImpl method construction.
@Override
public boolean construction(BaikePage baikePage) throws Exception {
// 词条标题(实体名)
String individualName = baikePage.getLemmaTitle();
String polysemantExplain = baikePage.getPolysemantExplain();
String url = baikePage.getUrl();
Individual movieIndividual = null;
// 查询词典中是否有该实体 有则查询返回 没有则创建返回 true表示这是本名
movieIndividual = this.queryIndividual(individualName, polysemantExplain, url, true, OntologyClassEnum.MOVIE);
constructionDAO.addObjectProperty(movieIndividual, "是", movieIndividual);
// 添加数据属性(描述和歧义说明)
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.MOVIE.getName());
constructionDAO.addDataProperty(movieIndividual, "picSrc", newPicName);
}
constructionDAO.addDataProperty(movieIndividual, "URL信息来源", url);
constructionDAO.addDataProperty(movieIndividual, "描述", lemmaSummary);
constructionDAO.addDataProperty(movieIndividual, "歧义说明", polysemantExplain);
// 添加基本信息
List<String> parameterNamesFilter = baikePage.getParameterNames();
List<String> parameterValuesFilter = baikePage.getParameterValues();
constructionDAO.addDataProperties(movieIndividual, parameterNamesFilter, parameterValuesFilter);
// 处理电影-公司对象
this.dealCompanys(movieIndividual, baikePage);
// 处理电影-公司对象(发行公司)
// this.dealCompanys(movieIndividual, baikePage);
// 处理电影-人物对象(导演)
this.dealCharacters(movieIndividual, baikePage);
// 处理电影-人物对象(主演)
// this.dealCharacters(movieIndividual, baikePage);
// 处理电影-人物对象(编剧)
// this.dealCharacters(movieIndividual, baikePage);
// 处理电影-人物对象(制片人)
// this.dealCharacters(movieIndividual, baikePage);
// 处理类型对象(类型-二级类)
this.dealMoiveType(movieIndividual, baikePage);
return false;
}
use of org.apache.jena.ontology.Individual in project answer-ontology-construction by YueHub.
the class MovieConstructionServiceImpl 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;
}
Aggregations