use of net.sourceforge.ondex.core.ConceptClass in project knetbuilder by Rothamsted.
the class GraphElementManipulation method oneToManyCollapse.
/**
* Creates a one-to-many collapsed concept by creating collapsed concept of
* a source to all targets. Source concept is NOT deleted by this method.
*
* @param graph
* @param source
* @param targets
*/
public static final Set<ONDEXConcept> oneToManyCollapse(ONDEXGraph graph, ONDEXConcept source, Collection<ONDEXConcept> targets) {
boolean createNewTarget = false;
Set<ONDEXConcept> result = new HashSet<ONDEXConcept>();
System.err.println("Targets number:" + targets.size());
for (ONDEXConcept target : targets) {
System.err.println(target.getOfType());
ConceptClass newClass = target.getOfType();
Set<ConceptClass> set = new HashSet<ConceptClass>();
set.add(newClass);
set.add(source.getOfType());
if (set.size() > 1) {
createNewTarget = true;
newClass = getCompoundConceptClass(graph, set);
}
DataSource newDataSource = target.getElementOf();
Set<DataSource> allDataSources = new HashSet<DataSource>();
allDataSources.add(newDataSource);
allDataSources.add(source.getElementOf());
if (allDataSources.size() > 1) {
createNewTarget = true;
newDataSource = getCompoundDataSource(graph, allDataSources);
}
ONDEXConcept realTarget = target;
if (createNewTarget) {
realTarget = copyConcept(graph, target, newClass, newDataSource);
copyRelations(graph, target, realTarget);
graph.deleteConcept(target.getId());
}
copyConceptData(graph, source, realTarget);
copyRelations(graph, source, realTarget);
result.add(realTarget);
}
return result;
}
use of net.sourceforge.ondex.core.ConceptClass in project knetbuilder by Rothamsted.
the class GraphElementManipulation method getCompoundConceptClass.
/**
* @param graph
* - graph
* @param ids
* - concept classes to compound
* @return - new concept class
* @author hindlem
* <p/>
* The method for creation of compound concept classes used during
* the collapsing of entities
*/
public static ConceptClass getCompoundConceptClass(ONDEXGraph graph, Collection<ConceptClass> ids) {
final TreeSet<String> sortedConceptClassConcat = new TreeSet<String>();
ConceptClass newCc = null;
for (ConceptClass id : ids) {
String[] compoundIds = id.getId().split(":");
if (compoundIds.length > 1) {
Collections.addAll(sortedConceptClassConcat, compoundIds);
} else {
sortedConceptClassConcat.add(id.getId());
}
}
if (sortedConceptClassConcat.size() == 0)
throw new RuntimeException("The set supplied must not be empty");
if (sortedConceptClassConcat.size() > 1) {
StringBuilder newCCName = new StringBuilder();
Iterator<String> ccit = sortedConceptClassConcat.iterator();
boolean first = true;
while (ccit.hasNext()) {
String ccName = ccit.next();
if (!first)
newCCName.append(':');
newCCName.append(ccName);
first = false;
}
String ccName = newCCName.toString();
newCc = graph.getMetaData().getConceptClass(ccName);
if (newCc == null) {
newCc = graph.getMetaData().getFactory().createConceptClass(ccName, ccName, "Collapsed Concept Class Set");
}
} else {
String ccName = sortedConceptClassConcat.iterator().next();
newCc = graph.getMetaData().getConceptClass(ccName);
if (newCc == null) {
newCc = graph.getMetaData().getFactory().createConceptClass(ccName, ccName, "Collapsed Concept Class Set");
}
}
return newCc;
}
use of net.sourceforge.ondex.core.ConceptClass in project knetbuilder by Rothamsted.
the class ViewConstruction method getRelationsOfConceptClasses.
/**
* Constructs the view containing all relations associated with particular
* concept class, using the string ids to define the class
* @param graph - graph to operate on
* determine which relation to include in the view.
*
* @return - resulting view
*/
public static Set<ONDEXRelation> getRelationsOfConceptClasses(ONDEXGraph graph, List<String> ccs) {
Set<ONDEXRelation> result = BitSetFunctions.create(graph, ONDEXRelation.class, new BitSet());
ONDEXGraphMetaData meta = graph.getMetaData();
for (String cc : ccs) {
ConceptClass ct = meta.getConceptClass(cc);
if (ct != null) {
result.addAll(graph.getRelationsOfConceptClass(ct));
}
}
return result;
}
use of net.sourceforge.ondex.core.ConceptClass in project knetbuilder by Rothamsted.
the class ViewConstruction method getConceptsOfTypes.
/**
* Return all of the concept of concept classes with provided ids in the graph
* @param graph - Ondex graph
* @param strIds - id of concept classes
*
* @return view
*/
public static final Set<ONDEXConcept> getConceptsOfTypes(ONDEXGraph graph, Collection<String> strIds) {
Set<ONDEXConcept> result = BitSetFunctions.create(graph, ONDEXConcept.class, new BitSet());
ConceptClass[] ccs = ControledVocabularyHelper.convertConceptClasses(graph, strIds);
for (ConceptClass cc : ccs) {
result.addAll(graph.getConceptsOfConceptClass(cc));
}
return result;
}
use of net.sourceforge.ondex.core.ConceptClass in project knetbuilder by Rothamsted.
the class MdHelper method createCC.
/**
* Get concpet class
*
* @param graph
* @param type
* @return
*/
public static ConceptClass createCC(final ONDEXGraph graph, final String type) {
final ONDEXGraphMetaData meta = graph.getMetaData();
ConceptClass cc = meta.getConceptClass(type);
if (cc == null)
cc = meta.getFactory().createConceptClass(type);
return cc;
}
Aggregations