private void addAttribute(Object value, Attribute attribute, ONDEXRelation relation, AttributeName att) { if (value != null) { if (attribute == null) { relation.createAttribute(att, value, false); } else { attribute.setValue(value); } } }
/** * Constructor wraps a given ONDEXRelation. * * @param sid * unique id * @param aog * LuceneONDEXGraph * @param r * ONDEXRelation */ LuceneRelation(long sid, LuceneONDEXGraph aog, ONDEXRelation r) { this(sid, aog, r.getId(), r.getFromConcept(), r.getToConcept(), r .getOfType()); this.parent = r; }
private static Set<ONDEXRelation> getRelationsWithAttribute(ONDEXGraph graph, ONDEXConcept c, AttributeName an) { BitSet set = new BitSet(); for (ONDEXRelation r : graph.getRelationsOfConcept(c)) { if (r.getFromConcept().equals(r.getToConcept())) continue; if (r.getAttribute(an) != null) set.set(r.getId()); } Set<ONDEXRelation> result = BitSetFunctions.create(graph, ONDEXRelation.class, set); return result; }
/** * Copies all context information from old relation to new relation. * * @param oldR * old ONDEXRelation * @param newR * new ONDEXRelation */ private void copyContext(ONDEXRelation oldR, ONDEXRelation newR) { // transfer context from old relation to new relation for (ONDEXConcept c : oldR.getTags()) { newR.addTag(c); } }
/** * Returns a concept's opposite one on a relation. * * @param c_curr the concept on the one end. * @param r_curr the relation. * @return the concept on the other end. */ private ONDEXConcept getOppositeConcept(ONDEXConcept c_curr, ONDEXRelation r_curr) { return (r_curr.getFromConcept().equals(c_curr)) ? r_curr.getToConcept() : r_curr.getFromConcept(); }
JSONObject relationJson= new JSONObject(); relationJson.put(JSONAttributeNames.ID, String.valueOf(rel.getId())); // relation ID. relationJson.put(JSONAttributeNames.FROMCONCEPT, String.valueOf(rel.getFromConcept().getId())); // relation source ID. relationJson.put(JSONAttributeNames.TOCONCEPT,String.valueOf(rel.getToConcept().getId())); // relation target ID. relationJson.put(JSONAttributeNames.OFTYPE, buildRelationType(rel.getOfType())); Set<EvidenceType> evidenceTypes= rel.getEvidence(); Set<Attribute> attributes= rel.getAttributes(); Set<ONDEXConcept> contexts= rel.getTags(); JSONObject contextsJson= new JSONObject(); for(ONDEXConcept context: contexts) {
throws NullValueException, AccessDeniedException { ONDEXRelation nr = null; Collection<EvidenceType> evidence = r.getEvidence(); Collection<ONDEXConcept> tags = new HashSet<ONDEXConcept>(r.getTags()); Collection<Attribute> rgdss = r.getAttributes(); if (r.getFromConcept().equals(original) && r.getToConcept().equals(original)) { nr = graph.getRelation(copyTarget, copyTarget, r.getOfType()); if (nr == null) nr = graph.createRelation(copyTarget, copyTarget, r.getOfType(), evidence); } else { if (r.getFromConcept().equals(original)) { nr = graph.getRelation(copyTarget, r.getToConcept(), r.getOfType()); if (nr == null) nr = graph.createRelation(copyTarget, r.getToConcept(), r.getOfType(), evidence); } else { nr = graph.getRelation(r.getFromConcept(), copyTarget, r.getOfType()); if (nr == null) nr = graph.createRelation(r.getFromConcept(), copyTarget, r.getOfType(), evidence); if (!nr.getTags().contains(tag)) nr.addTag(tag); if (nr.getAttribute(rattribute.getOfType()) == null)
ONDEXConcept from = r.getFromConcept(); ONDEXConcept to = r.getToConcept(); r.getEvidence()); for (ONDEXConcept c : r.getTags()) { newr.addTag(c); for (Attribute attr : r.getAttributes()) { newr.createAttribute(attr.getOfType(), attr.getValue(), attr.isDoIndex()); toDelete.add(r.getId());
/** * Transfers all relations that the old concept takes part into to the new * concept. * * @param oldC * old ONDEXConcept * @param newC * new ONDEXConcept */ private void transferRelations(ONDEXConcept oldC, ONDEXConcept newC) { // iterate over all relations of old concept for (ONDEXRelation oldR : graph.getRelationsOfConcept(oldC)) { ONDEXRelation newR = null; if (oldR.getFromConcept().equals(oldC)) { // old concept is from concept newR = graph.createRelation(newC, oldR.getToConcept(), oldR.getOfType(), oldR.getEvidence()); } else if (oldR.getToConcept().equals(oldC)) { // old concept is to concept newR = graph.createRelation(oldR.getFromConcept(), newC, oldR.getOfType(), oldR.getEvidence()); } // transfer context old to new for (ONDEXConcept c : oldR.getTags()) { newR.addTag(c); } } }
/** * Clone relation with having a new RelationType. * * @param oldR * old ONDEXRelation * @param newRT * new RelationType to use * @return new ONDEXRelation */ public ONDEXRelation clone(ONDEXRelation oldR, RelationType newRT) { // first clone concept with new ConceptClass ONDEXRelation newR = graph.getRelation(oldR.getFromConcept(), oldR.getToConcept(), oldR.getOfType()); if (newR == null) graph.createRelation(oldR.getFromConcept(), oldR.getToConcept(), oldR.getOfType(), oldR.getEvidence()); // copies everything else copyEverythingElse(oldR, newR); return newR; }
/** * For a given relation returns the target concept, observes the reverse * logic flag. * * @param r * ONDEXRelation * @return target concept */ private ONDEXConcept getTarget(ONDEXRelation r) { String relationType = r.getOfType().getFullname(); if (relationType == null) relationType = r.getOfType().getId(); if (relationTypeReverseLogic.contains(relationType)) { return r.getFromConcept(); } return r.getToConcept(); }
/** * This method will create a copy of the original relation between the * concepts specified. * * @param graph * - graph where this things live * @param from * - source concept of the copied relation * @param to * - target concept of the copied relation * @param r * - relation that will be copied */ public static void copyRelation(ONDEXGraph graph, ONDEXConcept from, ONDEXConcept to, ONDEXRelation r) { ONDEXRelation nr = null; Collection<EvidenceType> evidence = r.getEvidence(); Collection<ONDEXConcept> tags = new HashSet<ONDEXConcept>(r.getTags()); Collection<Attribute> rgdss = r.getAttributes(); nr = graph.createRelation(from, to, r.getOfType(), evidence); for (ONDEXConcept tag : tags) nr.addTag(tag); for (Attribute rattribute : rgdss) { cloneAttributeWithAttName(graph, r, nr, rattribute.getOfType()); } }
/** * Returns visibility for a given edge. * * @param edge * ONDEXRelation * @return is visible */ public boolean isVisible(ONDEXRelation edge) { if (edge == null) return false; return edge_visibility.get(edge.getId()) && vertex_visibility.get(edge.getFromConcept().getId()) && vertex_visibility.get(edge.getToConcept().getId()); }
/** * Creates a gds on relation only if it does not already exists * * @param target * - relation * @param newAttribute * - attribute to create * @throws AccessDeniedException * @throws NullValueException */ public static void addNewAttribute(ONDEXRelation target, Attribute newAttribute) throws NullValueException, AccessDeniedException { if (target.getAttribute(newAttribute.getOfType()) == null) target.createAttribute(newAttribute.getOfType(), newAttribute.getValue(), newAttribute.isDoIndex()); }
public static void changeAttributeValue(ONDEXEntity e, AttributeName n, Object value) { if (e instanceof ONDEXConcept) { ONDEXConcept c = (ONDEXConcept) e; boolean doIndex = c.getAttribute(n).isDoIndex(); c.deleteAttribute(n); c.createAttribute(n, value, doIndex); } if (e instanceof ONDEXRelation) { ONDEXRelation r = (ONDEXRelation) e; boolean doIndex = r.getAttribute(n).isDoIndex(); r.deleteAttribute(n); r.createAttribute(n, value, doIndex); } else { throw new IllegalArgumentException( "This method only works with Ondex concepts and relations."); } }
/** * Copies all Attribute from old relation to new relation. * * @param oldR * old ONDEXRelation * @param newR * new ONDEXRelation */ private void copyGDS(ONDEXRelation oldR, ONDEXRelation newR) { // iterate over all old Attribute for (Attribute attribute : oldR.getAttributes()) { // clone old Attribute on new relation only if not yet exists if (newR.getAttribute(attribute.getOfType()) != null) // old Attribute gets overridden newR.deleteAttribute(attribute.getOfType()); else newR.createAttribute(attribute.getOfType(), attribute.getValue(), attribute.isDoIndex()); } } }
public BitSet getMatchingIdSet(Set<ONDEXRelation> ov) throws NullValueException, EmptyStringException, AccessDeniedException{ BitSet result = new BitSet(); for(ONDEXRelation relation : ov){ boolean addToset = true; for(RelationAttributeChecker chk :conditions.values()){ if(!chk.check(relation)){ addToset = false; break; } } if(addToset)result.set(relation.getId()); } return result; }
/** * Pre-check for all relations that <i>may</i> be accepted by <code>isValid(ONDEXRelation, StateMachineDerivedPath)</code>. * * @param relation the relation to check * @return true if the relation is valid, ignoring the path tag */ public boolean isValid(ONDEXRelation relation) { return relation.getOfType().equals(rt); }
/** * Returns all outgoing relations of concept * * @param graph * - graph * @param c * - concept * @param exclude * - ignore retalions of these types * @return - set of relations */ public static final Set<ONDEXRelation> getOutgoingRelations(ONDEXGraph graph, ONDEXConcept c, RelationType... exclude) { Set<RelationType> toExclude = new HashSet<RelationType>(Arrays.asList(exclude)); Set<ONDEXRelation> result = new HashSet<ONDEXRelation>(); for (ONDEXRelation r : graph.getRelationsOfConcept(c)) { if (r.getFromConcept().equals(c) && !toExclude.contains(r.getOfType())) result.add(r); } return result; }
@Override protected Attribute retrieveRelationAttribute(AttributeName attributeName) { return parent.getAttribute(attributeName); }