Created
September 10, 2010 00:40
-
-
Save palexander/572842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
import java.util.Date; | |
import java.util.UUID; | |
import org.openrdf.model.URI; | |
import org.openrdf.model.impl.URIImpl; | |
import org.openrdf.repository.object.annotations.iri; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#Mapping_Metadata") | |
public class MappingMetadata implements Serializable { | |
private static final long serialVersionUID = -1506672559890791939L; | |
@iri(Constants.MAPPING_METADATA_PREFIX + "id") | |
URI id; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#One_To_One_Mapping") | |
URI dependency; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#comment") | |
String comment; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#date") | |
Date date; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#submitted_by") | |
Integer submittedBy; | |
/** | |
* Default no-arg constructor. | |
*/ | |
public MappingMetadata() { | |
generateId(); | |
} | |
public MappingMetadata(URI mappingId) { | |
this(); | |
this.dependency = mappingId; | |
} | |
/** | |
* Generate an id for this mapping. | |
*/ | |
private void generateId() { | |
this.id = new URIImpl(Constants.MAPPING_METADATA_PREFIX + UUID.randomUUID().toString()); | |
} | |
/** | |
* @return the id | |
*/ | |
public URI getId() { | |
return id; | |
} | |
/** | |
* @param id | |
* the id to set | |
*/ | |
public void setId(URI id) { | |
this.id = id; | |
} | |
/** | |
* @return the dependency | |
*/ | |
public URI getDependency() { | |
return dependency; | |
} | |
/** | |
* @param dependency | |
* the dependency to set | |
*/ | |
public void setDependency(URI dependency) { | |
this.dependency = dependency; | |
} | |
/** | |
* @return the comment | |
*/ | |
public String getComment() { | |
return comment; | |
} | |
/** | |
* @param comment | |
* the comment to set | |
*/ | |
public void setComment(String comment) { | |
this.comment = comment; | |
} | |
/** | |
* @return the date | |
*/ | |
public Date getDate() { | |
return date; | |
} | |
/** | |
* @param date | |
* the date to set | |
*/ | |
public void setDate(Date date) { | |
this.date = date; | |
} | |
/** | |
* @return the submittedBy | |
*/ | |
public Integer getSubmittedBy() { | |
return submittedBy; | |
} | |
/** | |
* @param submittedBy2 | |
* the submittedBy to set | |
*/ | |
public void setSubmittedBy(Integer submittedBy2) { | |
this.submittedBy = submittedBy2; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.Serializable; | |
import java.util.UUID; | |
import org.openrdf.model.URI; | |
import org.openrdf.model.impl.URIImpl; | |
import org.openrdf.repository.object.annotations.iri; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#One_To_One_Mapping") | |
public class OneToOneMapping implements Serializable { | |
private static final long serialVersionUID = 5668752344409465584L; | |
@iri(Constants.MAPPING_PREFIX + "id") | |
URI id; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#Mapping_metadata") | |
MappingMetadata metadata; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#source") | |
URI source; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#target") | |
URI target; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#relation") | |
URI relation; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#source_ontology_id") | |
Integer sourceOntologyId; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#target_ontology_id") | |
Integer targetOntologyId; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#created_in_source_ontology_version") | |
Integer createdInSourceOntologyVersion; | |
@iri("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#created_in_target_ontology_version") | |
Integer createdInTargetOntologyVersion; | |
/** | |
* Default no-arg constructor. | |
* */ | |
public OneToOneMapping() { | |
generateId(); | |
} | |
/** | |
* Generate an id for this mapping. | |
*/ | |
private void generateId() { | |
this.id = new URIImpl(Constants.MAPPING_PREFIX + UUID.randomUUID().toString()); | |
} | |
/** | |
* @return the metadata | |
*/ | |
public MappingMetadata getMetadata() { | |
return metadata; | |
} | |
/** | |
* @param metadata | |
* the metadata to set | |
*/ | |
public void setMetadata(MappingMetadata metadata) { | |
this.metadata = metadata; | |
} | |
/** | |
* @return the id | |
*/ | |
public URI getId() { | |
return id; | |
} | |
/** | |
* @param id | |
* the id to set | |
*/ | |
public void setId(URI id) { | |
this.id = id; | |
} | |
/** | |
* @return the source | |
*/ | |
public URI getSource() { | |
return source; | |
} | |
/** | |
* @param source | |
* the source to set | |
*/ | |
public void setSource(URI source) { | |
this.source = source; | |
} | |
/** | |
* @return the target | |
*/ | |
public URI getTarget() { | |
return target; | |
} | |
/** | |
* @param target | |
* the target to set | |
*/ | |
public void setTarget(URI target) { | |
this.target = target; | |
} | |
/** | |
* @return the relation | |
*/ | |
public URI getRelation() { | |
return relation; | |
} | |
/** | |
* @param relation | |
* the relation to set | |
*/ | |
public void setRelation(URI relation) { | |
this.relation = relation; | |
} | |
/** | |
* @return the sourceOntologyId | |
*/ | |
public Integer getSourceOntologyId() { | |
return sourceOntologyId; | |
} | |
/** | |
* @param sourceOntologyId | |
* the sourceOntologyId to set | |
*/ | |
public void setSourceOntologyId(Integer sourceOntologyId) { | |
this.sourceOntologyId = sourceOntologyId; | |
} | |
/** | |
* @return the targetOntologyId | |
*/ | |
public Integer getTargetOntologyId() { | |
return targetOntologyId; | |
} | |
/** | |
* @param targetOntologyId | |
* the targetOntologyId to set | |
*/ | |
public void setTargetOntologyId(Integer targetOntologyId) { | |
this.targetOntologyId = targetOntologyId; | |
} | |
/** | |
* @return the createdInSourceOntologyVersion | |
*/ | |
public Integer getCreatedInSourceOntologyVersion() { | |
return createdInSourceOntologyVersion; | |
} | |
/** | |
* @param createdInSourceOntologyVersion | |
* the createdInSourceOntologyVersion to set | |
*/ | |
public void setCreatedInSourceOntologyVersion( | |
Integer createdInSourceOntologyVersion) { | |
this.createdInSourceOntologyVersion = createdInSourceOntologyVersion; | |
} | |
/** | |
* @return the createdInTargetOntologyVersion | |
*/ | |
public Integer getCreatedInTargetOntologyVersion() { | |
return createdInTargetOntologyVersion; | |
} | |
/** | |
* @param createdInTargetOntologyVersion | |
* the createdInTargetOntologyVersion to set | |
*/ | |
public void setCreatedInTargetOntologyVersion( | |
Integer createdInTargetOntologyVersion) { | |
this.createdInTargetOntologyVersion = createdInTargetOntologyVersion; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Repository repository = new VirtuosoRepository("jdbc:virtuoso://localhost:1111/", "dba", "dba"); | |
repository.initialize(); | |
ObjectRepositoryFactory objectRepositoryFactory = new ObjectRepositoryFactory(); | |
ObjectRepository objectRepository = objectRepositoryFactory.createRepository(repository); | |
ObjectConnection con = objectRepository.getConnection(); | |
con.setAddContexts(new URIImpl("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs")); | |
OneToOneMapping mapping = new OneToOneMapping(); | |
// Instantiate a MappingMetadata object for the mapping | |
mapping.setMetadata(new MappingMetadata(mapping.getId())); | |
// Set Mapping properties | |
mapping.setSource(new URIImpl("http://purl.bioontology.org/ontology/ATMO/ATM_00000")); | |
mapping.setTarget(new URIImpl("http://purl.org/obo/owl/UBERON#UBERON_0001062")); | |
mapping.setRelation(new URIImpl("http://protege.stanford.edu/ontologies/mappings/mappings.rdfs#owl:sameAs")); | |
mapping.setSourceOntologyId(1099); | |
mapping.setTargetOntologyId(1404); | |
mapping.setCreatedInSourceOntologyVersion(44203); | |
mapping.setCreatedInTargetOntologyVersion(44301); | |
// Set metadata properties | |
mapping.getMetadata().setSubmittedBy(99); | |
try { | |
con.addObject(mapping.getId(), mapping); | |
} catch (RepositoryException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
try { | |
OneToOneMapping mappingToDelete = con.getObject(OneToOneMapping.class, mapping.getId()); | |
mappingToDelete.setId(null); | |
mappingToDelete.setMetadata(null); | |
mappingToDelete.setSource(null); | |
mappingToDelete.setTarget(null); | |
mappingToDelete.setRelation(null); | |
mappingToDelete.setSourceOntologyId(null); | |
mappingToDelete.setTargetOntologyId(null); | |
mappingToDelete.setCreatedInSourceOntologyVersion(null); | |
mappingToDelete.setCreatedInTargetOntologyVersion(null); | |
// Delete the mapping | |
con.removeDesignation(mappingToDelete, OneToOneMapping.class); | |
} catch (RepositoryException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} catch (QueryEvaluationException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment