Reconstitutes axioms in laconic justifications
@return A set of justifications whose axioms are reconstituted
427096
private Set<Explanation<E>> getReconstitutedLaconicJustifications() {
        // Simple, but not particularly efficient

        // What we do is examine the subclass axioms in an explanation
        // We merge axioms that have the same LHS and same source checker.  Although the
        // explanations that we operate on are already laconic, we end up producing explanations
        // that will be closer to the asserted axioms
        Map<OWLAxiom, Set<OWLAxiom>> sourceAxioms2OPlus = new HashMap<OWLAxiom, Set<OWLAxiom>>();

        for (Explanation<E> exp : allPreviouslyFoundJustifications) {
            for (OWLAxiom ax : exp.getAxioms()) {
                if (ont.containsAxiom(ax)) {
                    sourceAxioms2OPlus.put(ax, computeOPlus(Collections.singleton(ax)));
                }
            }
        }

        Set<Explanation<E>> reconstituedExplanations = new HashSet<Explanation<E>>();
        for (Explanation<E> laconicExp : foundLaconicJustifications) {
            // SubClass -> Source Axiom -> SubClass Axiom
            Map<OWLClass, Map<OWLAxiom, Set<OWLSubClassOfAxiom>>> lhs2SubClassAxiom = new HashMap<OWLClass, Map<OWLAxiom, Set<OWLSubClassOfAxiom>>>();

            Set<OWLAxiom> reconstituedAxioms = new HashSet<OWLAxiom>();
            for (OWLAxiom laconicAx : laconicExp.getAxioms()) {
                if (laconicAx instanceof OWLSubClassOfAxiom) {
                    OWLSubClassOfAxiom sca = (OWLSubClassOfAxiom) laconicAx;
                    if (sca.getSubClass().isAnonymous()) {
                        // We only merge stuff with a common NAMED lhs
                        reconstituedAxioms.add(sca);
                        continue;
                    }
                    Map<OWLAxiom, Set<OWLSubClassOfAxiom>> source2AxiomMap = lhs2SubClassAxiom.get(sca.getSubClass().asOWLClass());
                    if (source2AxiomMap == null) {
                        source2AxiomMap = new HashMap<OWLAxiom, Set<OWLSubClassOfAxiom>>();
                        lhs2SubClassAxiom.put(sca.getSubClass().asOWLClass(), source2AxiomMap);
                    }
                    for (OWLAxiom sourceAx : sourceAxioms2OPlus.keySet()) {
                        if (sourceAxioms2OPlus.get(sourceAx).contains(sca)) {
                            Set<OWLSubClassOfAxiom> subClassAxioms = source2AxiomMap.get(sourceAx);
                            if (subClassAxioms == null) {
                                subClassAxioms = new HashSet<OWLSubClassOfAxiom>();
                                source2AxiomMap.put(sourceAx, subClassAxioms);
                            }
                            subClassAxioms.add(sca);
                        }
                    }
                }
                else {
                    reconstituedAxioms.add(laconicAx);
                }
            }
            // Right, now we have sorted everything, we merge axioms that have a common LHS and common source
            Set<OWLSubClassOfAxiom> consumedAxioms = new HashSet<OWLSubClassOfAxiom>();
            for (OWLClass lhs : lhs2SubClassAxiom.keySet()) {
                Map<OWLAxiom, Set<OWLSubClassOfAxiom>> source2SubClassAxiom = lhs2SubClassAxiom.get(lhs);
                for (OWLAxiom source : source2SubClassAxiom.keySet()) {
                    Set<OWLClassExpression> rightHandSides = new HashSet<OWLClassExpression>();
                    for (OWLSubClassOfAxiom subClassAx : source2SubClassAxiom.get(source)) {
                        if (!consumedAxioms.contains(subClassAx)) {
                            rightHandSides.add(subClassAx.getSuperClass());
                            consumedAxioms.add(subClassAx);
                        }
                    }
                    if (rightHandSides.size() == 1) {
                        reconstituedAxioms.add(man.getOWLDataFactory().getOWLSubClassOfAxiom(lhs, rightHandSides.iterator().next()));
                    }
                    else if (rightHandSides.size() > 1) {
                        OWLObjectIntersectionOf conjunction = man.getOWLDataFactory().getOWLObjectIntersectionOf(rightHandSides);
                        reconstituedAxioms.add(man.getOWLDataFactory().getOWLSubClassOfAxiom(lhs, conjunction));
                    }
                }
            }
            Explanation<E> explanation = new Explanation<E>(laconicExp.getEntailment(), reconstituedAxioms);
            reconstituedExplanations.add(explanation);

        }
        return reconstituedExplanations;
    }
598073
private ConstraintSet solveEquality() {
    List<Constraint> current = eqConstraints;
    List<Constraint> next = Lists.newArrayList();
    boolean done = false;
    boolean solvable = this.solvable;

    TypeReplacement nextBindings = new TypeReplacement(bindings);
    while (!done) {
      done = true;
      // Iterative constraint solving algorithm with four cases
      for (Constraint c : current) {
        Type subtype = c.subtype.substitute(nextBindings.getBindings());
        Type supertype = c.supertype.substitute(nextBindings.getBindings());
        
        if (subtype.isFunctional() && supertype.isFunctional()) {
          // Case 1: <a,b> = <c,d> => a = c && b = d
          
          // Replace this constraint with the entailed subtype
          // constraints on argument/return types.
          next.add(new Constraint(supertype.getArgumentType(), subtype.getArgumentType()));
          next.add(new Constraint(subtype.getReturnType(), supertype.getReturnType()));
          done = false;
        } else if (!subtype.isFunctional() && supertype.isFunctional()) {
          // Case 2: A = <c,d> => A = <c,d> (if A is a type var, else fail)
          if (subtype.hasTypeVariables()) {
            nextBindings.add(subtype.getAtomicTypeVar(), supertype);
            done = false;
          } else {
            solvable = false;
          }
        } else if (subtype.isFunctional() && !supertype.isFunctional()) {
          // Case 3: <c,d> = A => A = <c,d> (if A is a type var, else fail)
          if (supertype.hasTypeVariables()) {
            nextBindings.add(supertype.getAtomicTypeVar(), subtype);
            done = false;
          } else {
            solvable = false;
          }
        } else {
          // Case 4: A = B => A = B
          if (subtype.hasTypeVariables() && supertype.hasTypeVariables()) {
            if (subtype.getAtomicTypeVar() != supertype.getAtomicTypeVar()) {
              nextBindings.add(subtype.getAtomicTypeVar(), supertype);
            }
          } else if (subtype.hasTypeVariables()) {
            nextBindings.add(subtype.getAtomicTypeVar(), supertype);
            done = false;
          } else if (supertype.hasTypeVariables()) {
            nextBindings.add(supertype.getAtomicTypeVar(), subtype);
            done = false;
          } else {
            if (!subtype.equals(supertype)) {
              solvable = false;
            }
          }
        }
      }

      current = next;
      next = Lists.newArrayList();
    }
    
    List<Constraint> newSubConstraints = Lists.newArrayList();
    for (Constraint c : subConstraints) {
      newSubConstraints.add(c.substitute(nextBindings.getBindings()));
    }
    return new ConstraintSet(Lists.newArrayList(), newSubConstraints, nextBindings,
        solvable, typeVarCounter);
  }
545051
protected Set<String> getPrevExpandedRows() {
		Set<String> prev = getComponentModel().prevExpandedRows;
		if (prev == null) {
			return Collections.emptySet();
		} else {
			return Collections.unmodifiableSet(prev);
		}
	}
1334663
public Set<Explanation<E>> computePreciseJustsOptimised(E entailment, int limit) throws OWLException {
        this.limit = limit;
        foundLaconicJustifications.clear();
        ExplanationGenerator<E> gen = explanationGeneratorFactory.createExplanationGenerator(axioms, this);
        Set<Explanation<E>> regularJusts = null;
        try {
            regularJusts = gen.getExplanations(entailment);
        }
        catch (ExplanationGeneratorInterruptedException e) {
            // We have interrupted the generator via our progress monitor
            return foundLaconicJustifications;
        }
        if (isCancelled()) {
            return foundLaconicJustifications;
        }
        lastRegularJusts.clear();

        // Initialise the current set of justifications with the regular justifications.
        allPreviouslyFoundJustifications = new HashSet<Explanation<E>>();
        allPreviouslyFoundJustifications.addAll(regularJusts);

//        Set<Explanation<E>> nonLaconicJusts = new HashSet<Explanation<E>>();
//        Set<Explanation<E>> laconicJusts = new HashSet<Explanation<E>>();

        Set<OWLAxiom> axiomsInPreviousOntology = new HashSet<OWLAxiom>();

        // We compute justifications until we can't find anymore
        while (true) {

            if (isCancelled()) {
                return getReconstitutedLaconicJustifications();
            }
            // Now we take the union of our current set of justifications and compute
            // O+ from this set.

            Set<OWLAxiom> unionOfAllJustifications = new HashSet<OWLAxiom>();
            for (Explanation<E> exp : allPreviouslyFoundJustifications) {
                unionOfAllJustifications.addAll(exp.getAxioms());
            }
            Set<OWLAxiom> oPlus = computeOPlus(unionOfAllJustifications);

            // Create our new ontology.
            Set<OWLAxiom> augmentedAxioms = new HashSet<OWLAxiom>(oPlus);

            ///////////////////////////////////////////////////////////////////////////
            // OPTIMISATION
            //////////////////////////////////////////////////////////////////////////

            // Exactly which axioms to we add the ontology?  We need to
            // limit the axioms that we add to O+ to limit the number of
            // intermediate justifications.  Without limiting the performance impact
            // can be HUGE.
            // Basically, if an checker at some stage appeared in a justification that we
            // found, but it never appears in O+ then we don't add it to the ontology.
            // The rationale behind this is that certain axioms such as equivalent classes
            // checker will never ever appear in O+ or in a precise justification.
            for (OWLAxiom ax : ont.getLogicalAxioms()) {
                // If we have found the checker previously in a justification
                // but our O+ doesn't contain it then we don't add it.
                if (unionOfAllJustifications.contains(ax) && !oPlus.contains(ax)) {
                    continue;
                }
                augmentedAxioms.add(ax);
            }

            //////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////

            // Next optimisation


            if (augmentedAxioms.equals(axiomsInPreviousOntology)) {
                break;
            }

            ExplanationGenerator<E> gen2 = explanationGeneratorFactory.createExplanationGenerator(augmentedAxioms, this);

            axiomsInPreviousOntology.clear();
            axiomsInPreviousOntology.addAll(augmentedAxioms);

            Set<Explanation> allPrevJustsCopy = new HashSet<Explanation>(allPreviouslyFoundJustifications);

            // Create a generator that gets ALL explanations from OPlus
            Set<Explanation<E>> currentJustifications = null;
            try {
                currentJustifications = gen2.getExplanations(entailment);
            }
            catch (ExplanationGeneratorInterruptedException e) {
                return getReconstitutedLaconicJustifications();
            }
            if (isCancelled()) {
                return getReconstitutedLaconicJustifications();
            }
            allPreviouslyFoundJustifications.addAll(currentJustifications);
            if (allPreviouslyFoundJustifications.equals(allPrevJustsCopy)) {
                break;
            }
            // The following code used to check if we had found enough laconic justifcations.  We don't need this
            // anymore - I don't think
//            for (Explanation<E> e : currentJustifications) {
//                if (nonLaconicJusts.contains(e)) {
//                    continue;
//                }
//                if (laconicJusts.contains(e)) {
//                    continue;
//                }
//                if (isLaconic(e)) {
//                    laconicJusts.add(e);
//                }
//                else {
//                    nonLaconicJusts.add(e);
//                }
//                if (laconicJusts.size() == limit) {
//                    return getReconstitutedLaconicJustifications(laconicJusts);
//                }
//            }
        }

//        Set<Explanation<E>> laconicJustifications = new HashSet<Explanation<E>>();
//
//        // We should now have our justifications that contain the set of precise justifications.
//        // We just need to know which ones are the precise justifications.
//        for (Explanation<E> justification : allPreviouslyFoundJustifications) {
//            if (nonLaconicJusts.contains(justification)) {
//                continue;
//            }
//            if (laconicJusts.contains(justification)) {
//                laconicJustifications.add(justification);
//            } else {
//                if (isLaconic(justification)) {
//                    laconicJustifications.add(justification);
//                }
//            }
//        }

        return getReconstitutedLaconicJustifications();
    }
621411
public Set<XExtension> getExtensions() {
		if (attributes != null) {
			return XAttributeUtils.extractExtensions(getAttributes());	
		} else {
			return Collections.emptySet();
		}
	}
1213242
public static Set<ModificationFeature>[] getChangedModifications(PhysicalEntity before,
		PhysicalEntity after)
	{
		Set<Modification> set1 = collectFeatures(before);
		Set<Modification> set2 = collectFeatures(after);

		Set<Modification> temp = new HashSet<Modification>(set1);
		set1.removeAll(set2);
		set2.removeAll(temp);

		// Remove common features that can be deemed semantically equivalent

		Set<Modification> furtherRemove = new HashSet<Modification>();

		for (Modification m1 : set1)
		{
			for (Modification m2 : set2)
			{
				if (furtherRemove.contains(m2)) continue;

				if (m1.getKey().equals(m2.getKey()))
				{
					furtherRemove.add(m1);
					furtherRemove.add(m2);
					break;
				}
			}
		}

		set1.removeAll(furtherRemove);
		set2.removeAll(furtherRemove);

		return new Set[]{collectFeatures(set2), collectFeatures(set1)};
	}
859407
public DecisionDefinitionEntity getPreviousDefinition() {
    DecisionDefinitionEntity previousDecisionDefinition = null;

    String previousDecisionDefinitionId = getPreviousDecisionDefinitionId();
    if (previousDecisionDefinitionId != null) {

      previousDecisionDefinition = loadDecisionDefinition(previousDecisionDefinitionId);

      if (previousDecisionDefinition == null) {
        resetPreviousDecisionDefinitionId();
        previousDecisionDefinitionId = getPreviousDecisionDefinitionId();

        if (previousDecisionDefinitionId != null) {
          previousDecisionDefinition = loadDecisionDefinition(previousDecisionDefinitionId);
        }
      }
    }

    return previousDecisionDefinition;
  }
1371102
public LightweightTypeReference resolve() {
		if (internalIsResolved())
			return resolvedTo;
		List<LightweightBoundTypeArgument> allHints = getAllHints();
		if (!allHints.isEmpty() && resolveWithHints(allHints)) {
			LightweightTypeReference result = internalGetResolvedTo();
			if (result != null) {
				return result;
			}
		}
		resolveAgainstConstraints();
		return resolvedTo;
	}
795141
public List<ConstraintDefinitionType<ValidationMappingDescriptor>> getAllConstraintDefinition()
   {
      List<ConstraintDefinitionType<ValidationMappingDescriptor>> list = new ArrayList<ConstraintDefinitionType<ValidationMappingDescriptor>>();
      List<Node> nodeList = model.get("constraint-definition");
      for(Node node: nodeList)
      {
         ConstraintDefinitionType<ValidationMappingDescriptor>  type = new ConstraintDefinitionTypeImpl<ValidationMappingDescriptor>(this, "constraint-definition", model, node);
         list.add(type);
      }
      return list;
   }
921709
private static Collection<AnnotationValue> getDirectAnnotation(AnnotatedObject m) {
        Collection<AnnotationValue> result = getDirectObjectAnnotations().get(m);
        if (result != null) {
            return result;
        }
        if (m.getAnnotationDescriptors().isEmpty()) {
            return Collections.<AnnotationValue> emptyList();
        }
        result = TypeQualifierResolver.resolveTypeQualifiers(m.getAnnotations());
        if (result.size() == 0) {
            result = Collections.<AnnotationValue> emptyList();
        }
        getDirectObjectAnnotations().put(m, result);
        return result;
    }
932218
public static List<ResolverRule> getResolverRules() {
		return Arrays.asList(
			ResolverRules.LOOKUP_CALL_BY_NAME,
			ResolverRules.FLATTEN_STAR_REFERENCE,
			ResolverRules.EXPAND_COLUMN_FUNCTIONS,
			ResolverRules.OVER_WINDOWS,
			ResolverRules.FIELD_RESOLVE,
			ResolverRules.FLATTEN_CALL,
			ResolverRules.RESOLVE_CALL_BY_ARGUMENTS,
			ResolverRules.VERIFY_NO_MORE_UNRESOLVED_EXPRESSIONS);
	}
208157
public UndefineArgument[] getDefines() throws BuildException {
    if (isReference()) {
      final DefineSet defset = (DefineSet) getCheckedRef(DefineSet.class, "DefineSet");
      return defset.getDefines();
    } else {
      if (isActive()) {
        final UndefineArgument[] defs = new UndefineArgument[this.defineList.size()];
        this.defineList.copyInto(defs);
        return defs;
      } else {
        return new UndefineArgument[0];
      }
    }
  }
1194511
@Override
    public boolean beforeSolve(ReconfigurationProblem r) {
        super.beforeSolve(r);
        for (int i = 0; i < aliases.size(); i++) {
            int capa = capacities.get(i);
            int[] alias = aliases.get(i);
            int[] cUse = cUsages.get(i);
            int[] dUses = new int[dUsages.get(i).length];
            for (IntVar dUseDim : dUsages.get(i)) {
                dUses[i++] = dUseDim.getLB();
            }
            r.getModel().post(new AliasedCumulatives(alias,
                    new int[]{capa},
                    cHosts, new int[][]{cUse}, cEnds,
                    dHosts, new int[][]{dUses}, dStarts,
                    associations));

        }
        return true;
    }
778763
private Set<String> getOutstandingEvaluatorsAndMarkExpired() {
    final Set<String> outstanding = new HashSet<>();
    for (final String previousEvaluatorId : restartEvaluators.getEvaluatorIds()) {
      if (getStateOfPreviousEvaluator(previousEvaluatorId) == EvaluatorRestartState.EXPECTED) {
        outstanding.add(previousEvaluatorId);
        setEvaluatorExpired(previousEvaluatorId);
      }
    }

    return outstanding;
  }
70781
@Override
	protected List<XExpression> getArguments() {
		List<XExpression> syntacticArguments = getSyntacticArguments();
		XExpression firstArgument = getFirstArgument();
		if (firstArgument != null) {
			return createArgumentList(firstArgument, syntacticArguments);
		}
		return syntacticArguments;
	}
1075446
private static ImmutableList<ReasonerQueryImpl> queryPlan(ReasonerQueryImpl query){
        ResolutionPlan resolutionPlan = query.resolutionPlan();

        ImmutableList<Atom> plan = resolutionPlan.plan();
        TransactionOLTP tx = query.tx();
        LinkedList<Atom> atoms = new LinkedList<>(plan);
        List<ReasonerQueryImpl> queries = new LinkedList<>();

        List<Atom> nonResolvableAtoms = new ArrayList<>();
        while (!atoms.isEmpty()) {
            Atom top = atoms.remove();
            if (top.isRuleResolvable()) {
                if (!nonResolvableAtoms.isEmpty()) {
                    queries.add(ReasonerQueries.create(nonResolvableAtoms, tx));
                    nonResolvableAtoms.clear();
                }
                queries.add(ReasonerQueries.atomic(top));
            } else {
                nonResolvableAtoms.add(top);
                if (atoms.isEmpty()) queries.add(ReasonerQueries.create(nonResolvableAtoms, tx));
            }
        }

        boolean refine = plan.size() != queries.size() && !query.requiresSchema();
        return refine? refine(queries) : ImmutableList.copyOf(queries);
    }
628977
@Override
    public IsaAtom toIsaAtom(){
        IsaAtom isaAtom = IsaAtom.create(getAttributeVariable(), new Variable(), getTypeId(), false, getParentQuery());
        Set<Statement> patterns = new HashSet<>();
        ReasonerQueries.atomic(isaAtom).getPattern().getPatterns().stream().flatMap(p -> p.statements().stream()).forEach(patterns::add);
        getMultiPredicate().stream().map(Predicate::getPattern).forEach(patterns::add);
        return ReasonerQueries.atomic(Graql.and(patterns), tx()).getAtom().toIsaAtom();
    }