Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package edu.isi.karma.modeling.ontology;
import com.hp.hpl.jena.ontology.ConversionException;
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.IntersectionClass;
import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntDocumentManager;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.ontology.UnionClass;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import org.slf4j.Logger;


class AutoGenerateLiteral{

private Resource r;

private OntResource ontResource;

private OntProperty ontProperty;

public String rdfsType="";

public AutoGenerateLiteral(){

this.r = null;

this.ontResource = null;

this.rdfsType = null;
}

public AutoGenerateLiteral( Resource r ){

this.r = r;

this.rdfsType = null;

//setOntResource(this.r);

}

public AutoGenerateLiteral( Resource r , String rdfsType){

this.r = r;

this.ontResource = (OntResource)r;

this.rdfsType = rdfsType;

//setOntResource(this.r);

}

public void setResource( Resource r ){

this.r = r;

}

public void setRdfsType(String rdfsType){

this.rdfsType = rdfsType;


}

public Resource getResource(){

return this.r;

}

public String getRdfsType(){

return this.rdfsType;

}



public OntResource getOntResource(){

return this.ontResource;

}

public void setOntProperty(OntResource ontR){

if(getOntResource() != null){

this.ontProperty = ontR.asProperty();

}else{

this.ontProperty = null;
}


}

public OntProperty getOntProperty(){

return this.ontProperty;

}

public String getLiteralType(){

OntResource ontR = getOntResource();

Boolean checkProperty = ontR.isDatatypeProperty();

String toAddType = "";

if(checkProperty){

setOntProperty(ontR);

OntProperty ontP = getOntProperty();

if(ontP != null){

toAddType = String.valueOf(ontP.getRange());

String[] findXMLSchema = toAddType.split("#");

for(int index = findXMLSchema.length-1 ; index >= 0 ; index++){

String checkXML = findXMLSchema[index];

if(checkXML.contains("XMLSchema")){

toAddType = findXMLSchema[index + 1];

break;

}

}


int length = toAddType.length();

if( ( !toAddType.equals("") ) && length > 0){

setRdfsType("xsd:");

rdfsType = getRdfsType();

rdfsType = rdfsType + toAddType;
return(rdfsType);

}else{

rdfsType = "";
return(rdfsType);
//logger.error("Empty rdfs type");

}

}else{

rdfsType = "";
return(rdfsType);
//logger.error("Error in getting ontology Property");

}

}else{

rdfsType = "";
return(rdfsType);
//logger.error("Not a Data type Property");

}
//return(rdfsType);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ public Label getResourceLabel(Resource r) {
logger.error("No Comment for resource:" + r.toString());
rdfsComment = "";
}
return new Label(r.getURI(), ns, prefix, rdfsLabel, rdfsComment);



String rdfsType = "";

AutoGenerateLiteral rdfsTypeGenerate = new AutoGenerateLiteral(r , rdfsType);
rdfsType = rdfsTypeGenerate.getLiteralType();

return new Label(r.getURI(), ns, prefix, rdfsLabel, rdfsComment , rdfsType);
}


Expand Down
23 changes: 23 additions & 0 deletions karma-common/src/main/java/edu/isi/karma/rep/alignment/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class Label implements Serializable {
private String ns;
private String prefix;
private String rdfsLabel;
private String rdfsType;
private String rdfsComment;

public Label(String uri, String ns, String prefix, String rdfsLabel, String rdfsComment) {
Expand All @@ -41,6 +42,17 @@ public Label(String uri, String ns, String prefix, String rdfsLabel, String rdfs
this.rdfsLabel = rdfsLabel;
this.rdfsComment = rdfsComment;
}

public Label(String uri, String ns, String prefix, String rdfsLabel, String rdfsComment, String rdfsType){

this.uri = uri;
this.ns = ns;
this.rdfsType = rdfsType;
this.prefix = prefix;
this.rdfsLabel = rdfsLabel;
this.rdfsComment = rdfsComment;

}

public Label(String uri, String ns, String prefix) {
this.init();
Expand All @@ -61,6 +73,7 @@ public Label(Label uri) {
this.uri = uri.getUri();
this.ns = uri.getNs();
this.prefix = uri.getPrefix();
this.rdfsType = uri.getRdfsType();
this.rdfsLabel = uri.getRdfsLabel();
this.rdfsComment = uri.getRdfsComment();
}
Expand All @@ -72,6 +85,7 @@ private void init() {
this.prefix = null;
this.rdfsLabel = null;
this.rdfsComment = null;
this.rdfsType = null;
}

public void setUri(String uri) {
Expand All @@ -95,6 +109,15 @@ public void setRdfsLabel(String label) {
public void setRdfsComment(String comment) {
this.rdfsComment = comment;
}

public void setRdfsType(String rdfsType){
this.rdfsType = rdfsType;
}

public String getRdfsType(){
return rdfsType;

}

public String getUri() {
return uri;
Expand Down