/** * Provides an available knowledge representation technology. See the * getSupportedKRs method for the set of supported KRTs. * * @param name * The name of the KRT. * @return A KR interface implementation. * @throws KRInterfaceNotSupportedException * If the name does not map to a known interface. * @throws KRInitFailedException * If the creation of the requested implementation failed. */ public static KRInterface getKR(String name) throws KRInterfaceNotSupportedException, KRInitFailedException { try { KRInterface krInterface = kr.containsKey(name) ? kr.get(name).newInstance() : null; if (krInterface == null) { throw new KRInterfaceNotSupportedException( "could not find KRT '" + name + "' as only these are available: " + kr.keySet() + "."); } else { return krInterface; } } catch (IllegalAccessException | InstantiationException e) { throw new KRInitFailedException("failed to initialize KRT '" + name + "'.", e); } }
/** * Provides a dependency graph for a certain knowledge representation. * * @param kri * The knowledge representation interface. * @return A DependencyGraph implementation. * @throws KRInterfaceNotSupportedException * If the interface does not map to a known implementation. * @throws KRInitFailedException * If the creation of the requested implementation failed. */ public static DependencyGraph<?> getDependencyGraph(KRInterface kri) throws KRInterfaceNotSupportedException, KRInitFailedException { try { DependencyGraph<?> graph = graphs.containsKey(kri.getClass()) ? graphs.get(kri.getClass()).newInstance() : null; if (graph == null) { throw new KRInterfaceNotSupportedException("could not find a dependency graph implementation for '" + KRFactory.getName(kri) + "' as only these are available: " + graphs.keySet() + "."); } else { return graph; } } catch (IllegalAccessException | InstantiationException e) { throw new KRInitFailedException( "failed to initialize a dependency graph for '" + KRFactory.getName(kri) + "'.", e); } } }