├── .gitignore ├── LICENSE ├── README.md ├── core-api ├── CHANGELOG.md ├── LICENSE ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── cyc │ │ │ ├── CoreServicesLoader.java │ │ │ ├── Cyc.java │ │ │ ├── CycApiEntryPoint.java │ │ │ ├── CycServicesLoader.java │ │ │ ├── DefaultNlApiServiceImpl.java │ │ │ ├── kb │ │ │ ├── ArgPosition.java │ │ │ ├── ArgUpdate.java │ │ │ ├── Assertion.java │ │ │ ├── BinaryPredicate.java │ │ │ ├── Context.java │ │ │ ├── DefaultContext.java │ │ │ ├── Fact.java │ │ │ ├── FirstOrderCollection.java │ │ │ ├── KbCollection.java │ │ │ ├── KbFunction.java │ │ │ ├── KbIndividual.java │ │ │ ├── KbObject.java │ │ │ ├── KbPredicate.java │ │ │ ├── KbStatus.java │ │ │ ├── KbTerm.java │ │ │ ├── Relation.java │ │ │ ├── Rule.java │ │ │ ├── SecondOrderCollection.java │ │ │ ├── Sentence.java │ │ │ ├── Symbol.java │ │ │ ├── Variable.java │ │ │ ├── exception │ │ │ │ ├── CreateException.java │ │ │ │ ├── DeleteException.java │ │ │ │ ├── InvalidFormulaInContextException.java │ │ │ │ ├── InvalidNameException.java │ │ │ │ ├── KbException.java │ │ │ │ ├── KbObjectNotFoundException.java │ │ │ │ ├── KbRuntimeException.java │ │ │ │ ├── KbServerSideException.java │ │ │ │ ├── KbTypeConflictException.java │ │ │ │ ├── KbTypeException.java │ │ │ │ ├── StaleKbObjectException.java │ │ │ │ ├── VariableArityException.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── spi │ │ │ │ ├── AssertionService.java │ │ │ │ ├── BinaryPredicateService.java │ │ │ │ ├── ContextService.java │ │ │ │ ├── FactService.java │ │ │ │ ├── FirstOrderCollectionService.java │ │ │ │ ├── KbApiService.java │ │ │ │ ├── KbCollectionService.java │ │ │ │ ├── KbFunctionService.java │ │ │ │ ├── KbIndividualService.java │ │ │ │ ├── KbPredicateService.java │ │ │ │ ├── KbService.java │ │ │ │ ├── KbTermService.java │ │ │ │ ├── RelationService.java │ │ │ │ ├── RuleService.java │ │ │ │ ├── SecondOrderCollectionService.java │ │ │ │ ├── SentenceService.java │ │ │ │ ├── SymbolService.java │ │ │ │ ├── VariableService.java │ │ │ │ └── package-info.java │ │ │ └── wrapper │ │ │ │ ├── AssertionWrapper.java │ │ │ │ ├── BinaryPredicateWrapper.java │ │ │ │ ├── ContextWrapper.java │ │ │ │ ├── FactWrapper.java │ │ │ │ ├── FirstOrderCollectionWrapper.java │ │ │ │ ├── KbCollectionWrapper.java │ │ │ │ ├── KbFunctionWrapper.java │ │ │ │ ├── KbIndividualWrapper.java │ │ │ │ ├── KbObjectWrapper.java │ │ │ │ ├── KbPredicateWrapper.java │ │ │ │ ├── KbTermWrapper.java │ │ │ │ ├── RelationWrapper.java │ │ │ │ ├── RuleWrapper.java │ │ │ │ ├── SecondOrderCollectionWrapper.java │ │ │ │ ├── SentenceWrapper.java │ │ │ │ ├── SymbolWrapper.java │ │ │ │ ├── VariableWrapper.java │ │ │ │ └── package-info.java │ │ │ ├── nl │ │ │ ├── GenerationMode.java │ │ │ ├── HtmlLinkType.java │ │ │ ├── NlForce.java │ │ │ ├── NlGenerationParams.java │ │ │ ├── Paraphrase.java │ │ │ ├── Paraphraser.java │ │ │ ├── SubParaphrase.java │ │ │ ├── package-info.java │ │ │ └── spi │ │ │ │ ├── NlApiService.java │ │ │ │ ├── ParaphraserFactory.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── query │ │ │ ├── InferenceAnswerIdentifier.java │ │ │ ├── InferenceIdentifier.java │ │ │ ├── InferenceStatus.java │ │ │ ├── InferenceSuspendReason.java │ │ │ ├── ModifiableQuerySpecification.java │ │ │ ├── ParaphrasedQueryAnswer.java │ │ │ ├── ProofIdentifier.java │ │ │ ├── ProofView.java │ │ │ ├── ProofViewGenerator.java │ │ │ ├── ProofViewMarshaller.java │ │ │ ├── ProofViewNode.java │ │ │ ├── ProofViewSpecification.java │ │ │ ├── Query.java │ │ │ ├── QueryAnswer.java │ │ │ ├── QueryAnswerExplanation.java │ │ │ ├── QueryAnswerExplanationGenerator.java │ │ │ ├── QueryAnswerExplanationSpecification.java │ │ │ ├── QueryAnswers.java │ │ │ ├── QueryListener.java │ │ │ ├── QueryResultSet.java │ │ │ ├── QueryRules.java │ │ │ ├── QuerySpecification.java │ │ │ ├── exception │ │ │ │ ├── ProofViewException.java │ │ │ │ ├── QueryConstructionException.java │ │ │ │ ├── QueryException.java │ │ │ │ ├── QueryRuntimeException.java │ │ │ │ └── package-info.java │ │ │ ├── graph │ │ │ │ ├── GraphNodeAbsolutePath.java │ │ │ │ └── package-info.java │ │ │ ├── metrics │ │ │ │ ├── InferenceMetric.java │ │ │ │ ├── InferenceMetrics.java │ │ │ │ ├── InferenceMetricsValues.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── parameters │ │ │ │ ├── Browsable.java │ │ │ │ ├── DisjunctionFreeElVarsPolicy.java │ │ │ │ ├── InferenceAnswerLanguage.java │ │ │ │ ├── InferenceMode.java │ │ │ │ ├── InferenceParameter.java │ │ │ │ ├── InferenceParameterGetter.java │ │ │ │ ├── InferenceParameterSetter.java │ │ │ │ ├── InferenceParameterSymbolValue.java │ │ │ │ ├── InferenceParameterValue.java │ │ │ │ ├── InferenceParameterValueDescription.java │ │ │ │ ├── InferenceParameters.java │ │ │ │ ├── ProblemReusePolicy.java │ │ │ │ ├── ProofValidationMode.java │ │ │ │ ├── ResultUniqueness.java │ │ │ │ ├── StandardInferenceMetric.java │ │ │ │ ├── TransitiveClosureMode.java │ │ │ │ └── package-info.java │ │ │ └── spi │ │ │ │ ├── ProofViewService.java │ │ │ │ ├── QueryAnswerExplanationService.java │ │ │ │ ├── QueryApiService.java │ │ │ │ ├── QueryService.java │ │ │ │ └── package-info.java │ │ │ └── session │ │ │ ├── CycAddress.java │ │ │ ├── CycAddressImpl.java │ │ │ ├── CycServerInfo.java │ │ │ ├── CycServerReleaseType.java │ │ │ ├── CycSession.java │ │ │ ├── CycSessionConfiguration.java │ │ │ ├── CycSessionConfigurationProperties.java │ │ │ ├── ServerAddress.java │ │ │ ├── SessionManager.java │ │ │ ├── SessionManagerConfiguration.java │ │ │ ├── SessionManagerConfigurationProperties.java │ │ │ ├── SessionOptions.java │ │ │ ├── exception │ │ │ ├── OpenCycUnsupportedFeatureException.java │ │ │ ├── SessionCommandException.java │ │ │ ├── SessionCommunicationException.java │ │ │ ├── SessionConfigurationException.java │ │ │ ├── SessionException.java │ │ │ ├── SessionInitializationException.java │ │ │ ├── SessionManagerConfigurationException.java │ │ │ ├── SessionManagerException.java │ │ │ ├── SessionRuntimeException.java │ │ │ ├── SessionServiceException.java │ │ │ ├── UnsupportedCycOperationException.java │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── spi │ │ │ ├── SessionApiService.java │ │ │ └── package-info.java │ └── resources │ │ └── com │ │ └── cyc │ │ └── core │ │ └── BuildInfo.properties │ └── site │ └── site.xml ├── pom.xml └── src └── site └── resources └── images └── api-stack.png /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | nbactions.xml 8 | nb-configuration.xml 9 | .classpath 10 | .project 11 | .settings/ 12 | *~ 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Cyc Java API Suite 2 | ================== 3 | 4 | The Cyc Java API Suite comprises a set of Java APIs (and implementations) for developing Cyc-based 5 | applications or otherwise accessing Cyc capabilities, and provides a layered suite of functionality. 6 | We have currently released the following Java libraries: 7 | 8 | * [Core API Specification](core-api/README.md): Core set of APIs for interacting with the Cyc 9 | inference engine and knowledge base. 10 | * [Core Client Implementation](core-client/README.md): Reference implementation for the Core API 11 | Specification. 12 | 13 | Additionally, the [Model Generator Suite](https://github.com/cycorp/model-generator-suite) is 14 | available in a separate repository. 15 | 16 | Further functionality will be rolled out in a series of releases, including the Knowledge 17 | Management, Natural Language, Structured Knowledge, and Administration APIs: 18 | 19 |
20 | ![Diagram of the Cyc API stack](../master/api-parent/src/site/resources/images/api-stack.png?raw=true 21 | "Cyc API Stack") 22 |
23 | 24 | 25 | Further Documentation 26 | --------------------- 27 | 28 | For the latest API documentation and news, or to ask questions, visit the 29 | [Cyc Developer Center](http://dev.cyc.com/). 30 | 31 | Code samples may be downloaded from the _Core API Use Cases_ project in the 32 | [Cyc Example Code](https://github.com/cycorp/example-code) repository. 33 | 34 | 35 | Contact 36 | ------- 37 | 38 | For questions about the APIs or general issues with using them, please visit the 39 | [Cyc Dev Center issues page](http://dev.cyc.com/issues/). 40 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/CycApiEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.cyc; 2 | 3 | /* 4 | * #%L 5 | * File: CycApiEntryPoint.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | /** 24 | * A marker service provider interface (SPI) for Cyc API entrypoints. This represents the primary 25 | * entry point into a Cyc API (e.g., Session API, KB API, Query API, etc.) and any API which extends 26 | * it should do so exactly once. 27 | * 28 | *

29 | * An API may have multiple services defined, but only the API's CycApiEntryPoint will be loaded, 30 | * and the primary service may then provide additional services. For example, the KB API's 31 | * {@link com.cyc.kb.spi.KbApiService} provides a number of other KB-related services 32 | * ({@link com.cyc.kb.spi.AssertionService}, {@link com.cyc.kb.spi.KbTermService}, etc.) To simplify 33 | * service loading, CycApiEntryPoints may have methods which accept a class that extends 34 | * {@link com.cyc.CycServicesLoader} to provide access to whatever service loader methods would be 35 | * appropriate; an example of this is 36 | * {@link com.cyc.query.spi.QueryApiService#getQueryExplanationFactoryServices(com.cyc.CoreServicesLoader) }. 37 | * 38 | *

39 | * Note that a CycApiEntryPoint may not be directly exposed to the calling application. Although 40 | * this is possible, method calls to a CycApiEntryPoint are often made through wrapper methods on 41 | * {@link Cyc}, and/or via static interface methods. 42 | * 43 | * @author nwinant 44 | */ 45 | public interface CycApiEntryPoint { 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/DefaultNlApiServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.cyc; 2 | 3 | /* 4 | * #%L 5 | * File: DefaultNlApiServiceImpl.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | import com.cyc.nl.Paraphraser; 25 | import com.cyc.nl.Paraphraser.ParaphrasableType; 26 | import com.cyc.nl.spi.NlApiService; 27 | import com.cyc.nl.spi.ParaphraserFactory; 28 | import org.slf4j.Logger; 29 | import org.slf4j.LoggerFactory; 30 | 31 | /** 32 | * Interface for generating structured paraphrases of terms. 33 | * 34 | * DefaultNlApiServiceImpl objects provide the ability to generate natural language strings for CycL 35 | * objects (e.g. sentences and terms). The basic DefaultNlApiServiceImpl implementation available 36 | * from baseclient will provide very basic paraphrasing functionality. If the NL API is available on 37 | * the classpath, the getParaphraser methods of this class will return a paraphraser 38 | * that is more flexible. The BasicParaphraser (returned if only the baseclient is 39 | * available) is compatible with all versions of Cyc (including OpenCyc). 40 | * 41 | * @author baxter 42 | * @param 43 | */ 44 | class DefaultNlApiServiceImpl implements NlApiService, ParaphraserFactory { 45 | 46 | //====| Fields |==========================================================================// 47 | 48 | private static final String BASIC_PARAPHRASER_NAME = "BasicParaphraser"; 49 | 50 | private static final String BASIC_PARAPHRASER_CLASS = "com.cyc.nl." + BASIC_PARAPHRASER_NAME; 51 | 52 | private static final Logger LOG = LoggerFactory.getLogger(DefaultNlApiServiceImpl.class); 53 | 54 | private final Paraphraser basicParaphraser; 55 | 56 | //====| Fields |==========================================================================// 57 | 58 | DefaultNlApiServiceImpl() { 59 | LOG.warn( 60 | "NL API is not on the classpath; Natural Language generation support will be limited."); 61 | Paraphraser paraphraser = null; 62 | try { 63 | paraphraser = (Paraphraser) Class.forName(BASIC_PARAPHRASER_CLASS).newInstance(); 64 | } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { 65 | final String msg = "Error loading " + BASIC_PARAPHRASER_NAME + ": " + ex; 66 | if (LOG.isDebugEnabled()) { 67 | LOG.error(msg, ex); 68 | } else { 69 | LOG.error(msg); 70 | } 71 | } 72 | basicParaphraser = paraphraser; 73 | } 74 | 75 | //====| NlApiService methods |============================================================// 76 | 77 | @Override 78 | public ParaphraserFactory getParaphraserFactory() { 79 | return this; 80 | } 81 | 82 | //====| ParaphraserFactory methods |======================================================// 83 | 84 | @Override 85 | public Paraphraser getParaphraser(final ParaphrasableType type) { 86 | return basicParaphraser; 87 | } 88 | 89 | @Override 90 | public boolean isBasicParaphraser(Paraphraser paraphraser) { 91 | return paraphraser.getClass().getCanonicalName().equals(BASIC_PARAPHRASER_CLASS); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/ArgPosition.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb; 2 | 3 | /* 4 | * #%L 5 | * File: ArgPosition.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * @author nwinant 28 | */ 29 | public interface ArgPosition { 30 | 31 | public ArgPosition deepCopy(); 32 | 33 | /** 34 | * Get the nesting depth of this arg position. Top-level argument positions have depth 1. 35 | * 36 | * @return the nesting depth of this arg position 37 | */ 38 | public int depth(); 39 | 40 | /** 41 | * Destructively extend this arg position by another arg position. 42 | * 43 | * @return this ArgPosition. 44 | */ 45 | public ArgPosition extend(ArgPosition otherArgPos); 46 | 47 | /** 48 | * Destructively extend this arg position by one argnum. 49 | * 50 | * @return this ArgPosition. 51 | */ 52 | public ArgPosition extend(Integer argnum); 53 | 54 | /** 55 | * Get the first element in this arg position's path. This is the argument number of the argument 56 | * of the top-level formula that contains this position. 57 | * 58 | * @return the argument number. 59 | */ 60 | public Integer first(); 61 | 62 | /** 63 | * Get the list of argnums for this arg position, from top level to deepest level. 64 | * 65 | * @return the list of argnums for this arg position, 66 | */ 67 | public List getPath(); 68 | 69 | /** 70 | * Check if this arg position is for an ancestor of another arg position. 71 | * 72 | * @return true iff his arg position is for an ancestor of otherArgPosition 73 | */ 74 | public boolean isPrefixOf(ArgPosition otherArgPositionI); 75 | 76 | /** 77 | * Get the argnum of the designated argument in its immediate context. 78 | * 79 | * @return the argnum of the designated argument 80 | */ 81 | public Integer last(); 82 | 83 | /** 84 | * Does this arg position match candidate? 85 | * 86 | * @param matchEmpty Should we match the null arg position? 87 | * @return true iff this arg position matches candidate 88 | */ 89 | public boolean matchingArgPosition(ArgPosition candidate, boolean matchEmpty); 90 | 91 | /** 92 | * Destructively modify this ArgPosition to be its parent arg position. 93 | * 94 | * @return this ArgPosition. 95 | */ 96 | public ArgPosition toParent(); 97 | 98 | public String stringApiValue(); 99 | } 100 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/ArgUpdate.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb; 2 | 3 | /* 4 | * #%L 5 | * File: ArgUpdate.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | /** 24 | * 25 | * @author daves 26 | */ 27 | public interface ArgUpdate { 28 | 29 | public ArgPosition getArgPosition(); 30 | 31 | public ArgUpdateOperation getOperation(); 32 | 33 | public Object getValue(); 34 | 35 | public static enum ArgUpdateOperation { 36 | SET(":SET"), 37 | INSERT_BEFORE(":INSERT-BEFORE"), 38 | INSERT_AFTER(":INSERT-AFTER"), 39 | DELETE(":DELETE"); 40 | 41 | private final String name; 42 | 43 | ArgUpdateOperation(String name) { 44 | this.name = name; 45 | } 46 | 47 | public String toName() { 48 | return name; 49 | } 50 | 51 | public static ArgUpdateOperation fromValue(String symbol) { 52 | for (ArgUpdateOperation op : ArgUpdateOperation.values()) { 53 | if (op.toName().equals(symbol)) { 54 | return op; 55 | } 56 | } 57 | return valueOf(symbol); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/DefaultContext.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb; 2 | 3 | /* 4 | * #%L 5 | * File: DefaultContext.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * An immutable object interface to store default contexts for assertions 26 | * and queries. 27 | * 28 | * @author Vijay Raj 29 | * @version $Id: DefaultContext.java 185299 2019-01-14 16:15:35Z daves $ 30 | */ 31 | public interface DefaultContext { 32 | 33 | public Context forAssertion(); 34 | 35 | public Context forQuery(); 36 | } 37 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/KbStatus.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb; 2 | 3 | /* 4 | * #%L 5 | * File: KbStatus.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * An enumeration describing the existential status of a KB entity, and its 26 | * compatibility with a particular semantic object type. 27 | * 28 | * @author nwinant 29 | */ 30 | public enum KbStatus { 31 | EXISTS_AS_TYPE, 32 | EXISTS_WITH_COMPATIBLE_TYPE, 33 | EXISTS_WITH_TYPE_CONFLICT, 34 | DOES_NOT_EXIST; 35 | } 36 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/SecondOrderCollection.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb; 2 | 3 | import com.cyc.Cyc; 4 | import com.cyc.kb.exception.CreateException; 5 | import com.cyc.kb.exception.KbTypeException; 6 | import com.cyc.kb.spi.SecondOrderCollectionService; 7 | 8 | /* 9 | * #%L 10 | * File: SecondOrderCollection.java 11 | * Project: Core API 12 | * %% 13 | * Copyright (C) 2015 - 2019 Cycorp, Inc 14 | * %% 15 | * Licensed under the Apache License, Version 2.0 (the "License"); 16 | * you may not use this file except in compliance with the License. 17 | * You may obtain a copy of the License at 18 | * 19 | * http://www.apache.org/licenses/LICENSE-2.0 20 | * 21 | * Unless required by applicable law or agreed to in writing, software 22 | * distributed under the License is distributed on an "AS IS" BASIS, 23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 | * See the License for the specific language governing permissions and 25 | * limitations under the License. 26 | * #L% 27 | */ 28 | 29 | /** 30 | * The interface for {@link KbCollection}s whose instances are 31 | * {@link FirstOrderCollection}s. 32 | * 33 | * @author vijay 34 | */ 35 | public interface SecondOrderCollection extends KbCollection { 36 | 37 | //====| Factory methods |=================================================================// 38 | 39 | /** 40 | * Get the SecondOrderCollection with the name nameOrId. This static 41 | * method wraps a call to {@link SecondOrderCollectionService#get(java.lang.String) }; see that 42 | * method's documentation for more details. 43 | * 44 | * @param nameOrId the string representation or the HLID of the #$SecondOrderCollection 45 | * 46 | * @return a new SecondOrderCollection 47 | * 48 | * @throws KbTypeException 49 | * @throws CreateException 50 | */ 51 | public static SecondOrderCollection get(String nameOrId) 52 | throws KbTypeException, CreateException { 53 | return Cyc.getSecondOrderCollectionService().get(nameOrId); 54 | } 55 | 56 | public static SecondOrderCollection findOrCreate(String nameOrId) throws CreateException, KbTypeException { 57 | return Cyc.getSecondOrderCollectionService().findOrCreate(nameOrId); 58 | } 59 | 60 | public static SecondOrderCollection findOrCreate(String nameOrId, String constraintColStr) 61 | throws CreateException, KbTypeException { 62 | return Cyc.getSecondOrderCollectionService().findOrCreate(nameOrId, constraintColStr); 63 | } 64 | 65 | public static SecondOrderCollection findOrCreate(String nameOrId, String constraintColStr, String ctxStr) 66 | throws CreateException, KbTypeException { 67 | return Cyc.getSecondOrderCollectionService().findOrCreate(nameOrId, constraintColStr, ctxStr); 68 | } 69 | 70 | public static SecondOrderCollection findOrCreate(String nameOrId, KbCollection constraintCol) 71 | throws CreateException, KbTypeException { 72 | return Cyc.getSecondOrderCollectionService().findOrCreate(nameOrId, constraintCol); 73 | } 74 | 75 | public static SecondOrderCollection findOrCreate(String nameOrId, KbCollection constraintCol, Context ctx) 76 | throws CreateException, KbTypeException { 77 | return Cyc.getSecondOrderCollectionService().findOrCreate(nameOrId, constraintCol, ctx); 78 | } 79 | 80 | public static boolean existsAsType(String nameOrId) { 81 | return Cyc.getSecondOrderCollectionService().existsAsType(nameOrId); 82 | } 83 | 84 | public static KbStatus getStatus(String nameOrId) { 85 | return Cyc.getSecondOrderCollectionService().getStatus(nameOrId); 86 | } 87 | 88 | //====| Interface methods |===============================================================// 89 | 90 | } 91 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/Symbol.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb; 2 | 3 | import com.cyc.Cyc; 4 | import com.cyc.kb.exception.KbTypeException; 5 | import com.cyc.kb.spi.SymbolService; 6 | 7 | 8 | /* 9 | * #%L 10 | * File: Symbol.java 11 | * Project: Core API 12 | * %% 13 | * Copyright (C) 2015 - 2019 Cycorp, Inc 14 | * %% 15 | * Licensed under the Apache License, Version 2.0 (the "License"); 16 | * you may not use this file except in compliance with the License. 17 | * You may obtain a copy of the License at 18 | * 19 | * http://www.apache.org/licenses/LICENSE-2.0 20 | * 21 | * Unless required by applicable law or agreed to in writing, software 22 | * distributed under the License is distributed on an "AS IS" BASIS, 23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 | * See the License for the specific language governing permissions and 25 | * limitations under the License. 26 | * #L% 27 | */ 28 | 29 | /** 30 | * The interface for symbols of the SubL language. Symbols are 31 | * occasionally referenced in CycL assertions, most notably those 32 | * that denote SubL functions that test for membership in a 33 | * collection or perform simple functions like string manipulation or 34 | * arithmetic. 35 | * 36 | * @author baxter 37 | */ 38 | public interface Symbol extends KbObject { 39 | 40 | //====| Factory methods |=================================================================// 41 | 42 | /** 43 | * Creates an instance of #$CycLSubLSymbol represented by symStr in the underlying KB. This static 44 | * method wraps a call to {@link SymbolService#get(java.lang.String) }; see that method's 45 | * documentation for more details. 46 | * 47 | * @param symStr the string representing an #$CycLSubLSymbol in the KB 48 | * 49 | * @return the Symbol representing an #$CycLSubLSymbol in the KB 50 | * 51 | * @throws KbTypeException Symbols are created on demand and are not expected to throw any 52 | * exception 53 | */ 54 | public static Symbol get(String symStr) throws KbTypeException { 55 | return Cyc.getSymbolService().get(symStr); 56 | } 57 | 58 | //====| Interface methods |===============================================================// 59 | 60 | } 61 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/Variable.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb; 2 | 3 | import com.cyc.Cyc; 4 | import com.cyc.kb.exception.KbTypeException; 5 | import com.cyc.kb.spi.VariableService; 6 | 7 | /* 8 | * #%L 9 | * File: Variable.java 10 | * Project: Core API 11 | * %% 12 | * Copyright (C) 2015 - 2019 Cycorp, Inc 13 | * %% 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * #L% 26 | */ 27 | /** 28 | * The interface for CycL variables. Variables are used in 29 | * quantified {@link Sentence}s and in Queries. 30 | * 31 | * @author vijay 32 | */ 33 | public interface Variable extends KbObject { 34 | 35 | //====| Factory methods |=================================================================// 36 | 37 | /** 38 | * Creates an instance of #$CycLVariable represented by varStr in the underlying KB. This static 39 | * method wraps a call to {@link VariableService#get(java.lang.String) }; see that method's 40 | * documentation for more details. 41 | * 42 | * @param varStr the string representing an #$CycLVariable in the KB 43 | * 44 | * @return the Variable representing an #$CycLVariable in the KB 45 | * 46 | * @throws KbTypeException if the term represented by varStr is not an instance of #$CycLVariable 47 | * and cannot be made into one. 48 | * 49 | * Symbols are created on demand and are not expected to throw any exception 50 | */ 51 | public static Variable get(String varStr) throws KbTypeException { 52 | return Cyc.getVariableService().get(varStr); 53 | } 54 | 55 | //====| Interface methods |===============================================================// 56 | 57 | /** 58 | * Get the name of this variable. Does not include the leading '?' character. 59 | * 60 | * @return the name. 61 | */ 62 | String getName(); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/CreateException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: CreateException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * Thrown when code fails to find or create something from the Cyc KB. {@link KbTypeException} and 28 | * {@link KbTypeConflictException} are not subclasses because they do not indicate if the underlying 29 | * object is not in the KB. 30 | * 31 | * @author Vijay Raj 32 | * @version $Id: CreateException.java 185299 2019-01-14 16:15:35Z daves $ 33 | */ 34 | public class CreateException extends KbException { 35 | 36 | //====| Factory methods |=================================================================// 37 | 38 | /** 39 | * Converts a Throwable to a CreateException. If the Throwable is a 40 | * CreateException, it will be passed through unmodified; otherwise, it will be wrapped 41 | * in a new CreateException. 42 | * 43 | * @param cause the Throwable to convert 44 | * 45 | * @return a CreateException 46 | */ 47 | public static CreateException fromThrowable(Throwable cause) { 48 | return (cause instanceof CreateException) 49 | ? (CreateException) cause 50 | : new CreateException(cause); 51 | } 52 | 53 | /** 54 | * Converts a Throwable to a CreateException with the specified detail message. If the 55 | * Throwable is a CreateException and if the Throwable's message is identical to the 56 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 57 | * a new CreateException with the detail message. 58 | * 59 | * @param cause the Throwable to convert 60 | * @param message the specified detail message 61 | * 62 | * @return a CreateException 63 | */ 64 | public static CreateException fromThrowable(String message, Throwable cause) { 65 | return (cause instanceof CreateException && Objects.equals(message, cause.getMessage())) 66 | ? (CreateException) cause 67 | : new CreateException(message, cause); 68 | } 69 | 70 | //====| Construction |====================================================================// 71 | 72 | protected CreateException(Throwable cause) { 73 | super(cause); 74 | } 75 | 76 | public CreateException(String msg) { 77 | super(msg); 78 | } 79 | 80 | protected CreateException(String msg, Throwable cause) { 81 | super(msg, cause); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/DeleteException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: DeleteException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * Thrown when code fails to delete something from the Cyc KB. 28 | * 29 | * @author Nathan Winant 30 | * @version $Id: DeleteException.java 185299 2019-01-14 16:15:35Z daves $ 31 | */ 32 | public class DeleteException extends KbException { 33 | 34 | //====| Factory methods |=================================================================// 35 | 36 | /** 37 | * Converts a Throwable to a DeleteException. If the Throwable is a 38 | * DeleteException, it will be passed through unmodified; otherwise, it will be wrapped 39 | * in a new DeleteException. 40 | * 41 | * @param cause the Throwable to convert 42 | * 43 | * @return a DeleteException 44 | */ 45 | public static DeleteException fromThrowable(Throwable cause) { 46 | return (cause instanceof DeleteException) 47 | ? (DeleteException) cause 48 | : new DeleteException(cause); 49 | } 50 | 51 | /** 52 | * Converts a Throwable to a DeleteException with the specified detail message. If the 53 | * Throwable is a DeleteException and if the Throwable's message is identical to the 54 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 55 | * a new DeleteException with the detail message. 56 | * 57 | * @param cause the Throwable to convert 58 | * @param message the specified detail message 59 | * 60 | * @return a DeleteException 61 | */ 62 | public static DeleteException fromThrowable(String message, Throwable cause) { 63 | return (cause instanceof DeleteException && Objects.equals(message, cause.getMessage())) 64 | ? (DeleteException) cause 65 | : new DeleteException(message, cause); 66 | } 67 | 68 | //====| Construction |====================================================================// 69 | 70 | protected DeleteException(Throwable cause) { 71 | super(cause); 72 | } 73 | 74 | public DeleteException(String msg) { 75 | super(msg); 76 | } 77 | 78 | protected DeleteException(String msg, Throwable cause) { 79 | super(msg, cause); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/InvalidFormulaInContextException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: InvalidFormulaInContextException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * Thrown when the Cyc does not allow the specified formula to be true in the specified context. 28 | * It does not distinguish between semantic and syntactic errors. 29 | * 30 | * @author Vijay Raj 31 | * @version $Id: InvalidFormulaInContextException.java 185299 2019-01-14 16:15:35Z daves $ 32 | */ 33 | public class InvalidFormulaInContextException extends CreateException { 34 | 35 | //====| Factory methods |=================================================================// 36 | 37 | /** 38 | * Converts a Throwable to a InvalidFormulaInContextException. If the Throwable is a 39 | * InvalidFormulaInContextException, it will be passed through unmodified; otherwise, it will be wrapped 40 | * in a new InvalidFormulaInContextException. 41 | * 42 | * @param cause the Throwable to convert 43 | * 44 | * @return a InvalidFormulaInContextException 45 | */ 46 | public static InvalidFormulaInContextException fromThrowable(Throwable cause) { 47 | return (cause instanceof InvalidFormulaInContextException) 48 | ? (InvalidFormulaInContextException) cause 49 | : new InvalidFormulaInContextException(cause); 50 | } 51 | 52 | /** 53 | * Converts a Throwable to a InvalidFormulaInContextException with the specified detail message. If the 54 | * Throwable is a InvalidFormulaInContextException and if the Throwable's message is identical to the 55 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 56 | * a new InvalidFormulaInContextException with the detail message. 57 | * 58 | * @param cause the Throwable to convert 59 | * @param message the specified detail message 60 | * 61 | * @return a InvalidFormulaInContextException 62 | */ 63 | public static InvalidFormulaInContextException fromThrowable(String message, Throwable cause) { 64 | return (cause instanceof InvalidFormulaInContextException && Objects.equals(message, cause.getMessage())) 65 | ? (InvalidFormulaInContextException) cause 66 | : new InvalidFormulaInContextException(message, cause); 67 | } 68 | 69 | //====| Construction |====================================================================// 70 | 71 | protected InvalidFormulaInContextException(Throwable cause) { 72 | super(cause); 73 | } 74 | 75 | public InvalidFormulaInContextException(String msg) { 76 | super(msg); 77 | } 78 | 79 | protected InvalidFormulaInContextException(String msg, Throwable cause) { 80 | super(msg, cause); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/InvalidNameException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: InvalidNameException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * Thrown when code attempts to create a KB entity with an invalid name. 28 | * 29 | * @author Nathan Winant 30 | * @version $Id: InvalidNameException.java 185299 2019-01-14 16:15:35Z daves $ 31 | */ 32 | // @todo specify what the requirements are for a Constant name. 33 | 34 | public class InvalidNameException extends CreateException { 35 | 36 | //====| Factory methods |=================================================================// 37 | 38 | /** 39 | * Converts a Throwable to a InvalidNameException. If the Throwable is a 40 | * InvalidNameException, it will be passed through unmodified; otherwise, it will be wrapped 41 | * in a new InvalidNameException. 42 | * 43 | * @param cause the Throwable to convert 44 | * 45 | * @return a InvalidNameException 46 | */ 47 | public static InvalidNameException fromThrowable(Throwable cause) { 48 | return (cause instanceof InvalidNameException) 49 | ? (InvalidNameException) cause 50 | : new InvalidNameException(cause); 51 | } 52 | 53 | /** 54 | * Converts a Throwable to a InvalidNameException with the specified detail message. If the 55 | * Throwable is a InvalidNameException and if the Throwable's message is identical to the 56 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 57 | * a new InvalidNameException with the detail message. 58 | * 59 | * @param cause the Throwable to convert 60 | * @param message the specified detail message 61 | * 62 | * @return a InvalidNameException 63 | */ 64 | public static InvalidNameException fromThrowable(String message, Throwable cause) { 65 | return (cause instanceof InvalidNameException && Objects.equals(message, cause.getMessage())) 66 | ? (InvalidNameException) cause 67 | : new InvalidNameException(message, cause); 68 | } 69 | 70 | //====| Construction |====================================================================// 71 | 72 | protected InvalidNameException(Throwable cause) { 73 | super(cause); 74 | } 75 | 76 | public InvalidNameException(String msg) { 77 | super(msg); 78 | } 79 | 80 | protected InvalidNameException(String msg, Throwable cause) { 81 | super(msg, cause); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/KbException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: KbException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * Root class for exceptions thrown by the KB API. 28 | * 29 | * @author David Baxter 30 | * @version $Id: KbException.java 185299 2019-01-14 16:15:35Z daves $ 31 | */ 32 | public class KbException extends Exception { 33 | 34 | //====| Factory methods |=================================================================// 35 | 36 | /** 37 | * Converts a Throwable to a KbException. If the Throwable is a 38 | * KbException, it will be passed through unmodified; otherwise, it will be wrapped 39 | * in a new KbException. 40 | * 41 | * @param cause the Throwable to convert 42 | * 43 | * @return a KbException 44 | */ 45 | public static KbException fromThrowable(Throwable cause) { 46 | return (cause instanceof KbException) 47 | ? (KbException) cause 48 | : new KbException(cause); 49 | } 50 | 51 | /** 52 | * Converts a Throwable to a KbException with the specified detail message. If the 53 | * Throwable is a KbException and if the Throwable's message is identical to the 54 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 55 | * a new KbException with the detail message. 56 | * 57 | * @param cause the Throwable to convert 58 | * @param message the specified detail message 59 | * 60 | * @return a KbException 61 | */ 62 | public static KbException fromThrowable(String message, Throwable cause) { 63 | return (cause instanceof KbException && Objects.equals(message, cause.getMessage())) 64 | ? (KbException) cause 65 | : new KbException(message, cause); 66 | } 67 | 68 | //====| Construction |====================================================================// 69 | 70 | protected KbException(Throwable cause) { 71 | super(cause); 72 | } 73 | 74 | public KbException(String msg) { 75 | super(msg); 76 | } 77 | 78 | protected KbException(String msg, Throwable cause) { 79 | super(msg, cause); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/KbObjectNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: KbObjectNotFoundException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * Thrown when a term or a formula cannot be found from the specified 28 | * context. 29 | * 30 | * @author Vijay Raj 31 | * @version $Id: KbObjectNotFoundException.java 185299 2019-01-14 16:15:35Z daves $ 32 | */ 33 | /* 34 | */ 35 | public class KbObjectNotFoundException extends CreateException { 36 | 37 | //====| Factory methods |=================================================================// 38 | 39 | /** 40 | * Converts a Throwable to a KbObjectNotFoundException. If the Throwable is a 41 | * KbObjectNotFoundException, it will be passed through unmodified; otherwise, it will be wrapped 42 | * in a new KbObjectNotFoundException. 43 | * 44 | * @param cause the Throwable to convert 45 | * 46 | * @return a KbObjectNotFoundException 47 | */ 48 | public static KbObjectNotFoundException fromThrowable(Throwable cause) { 49 | return (cause instanceof KbObjectNotFoundException) 50 | ? (KbObjectNotFoundException) cause 51 | : new KbObjectNotFoundException(cause); 52 | } 53 | 54 | /** 55 | * Converts a Throwable to a KbObjectNotFoundException with the specified detail message. If the 56 | * Throwable is a KbObjectNotFoundException and if the Throwable's message is identical to the 57 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 58 | * a new KbObjectNotFoundException with the detail message. 59 | * 60 | * @param cause the Throwable to convert 61 | * @param message the specified detail message 62 | * 63 | * @return a KbObjectNotFoundException 64 | */ 65 | public static KbObjectNotFoundException fromThrowable(String message, Throwable cause) { 66 | return (cause instanceof KbObjectNotFoundException && Objects.equals(message, cause.getMessage())) 67 | ? (KbObjectNotFoundException) cause 68 | : new KbObjectNotFoundException(message, cause); 69 | } 70 | 71 | //====| Construction |====================================================================// 72 | 73 | protected KbObjectNotFoundException(Throwable cause) { 74 | super(cause); 75 | } 76 | 77 | public KbObjectNotFoundException(String msg) { 78 | super(msg); 79 | } 80 | 81 | protected KbObjectNotFoundException(String msg, Throwable cause) { 82 | super(msg, cause); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/KbRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.io.IOException; 4 | import java.net.UnknownHostException; 5 | import java.util.Objects; 6 | 7 | /* 8 | * #%L 9 | * File: KbRuntimeException.java 10 | * Project: Core API 11 | * %% 12 | * Copyright (C) 2015 - 2019 Cycorp, Inc 13 | * %% 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * #L% 26 | */ 27 | /** 28 | * Root class for runtime exceptions thrown by the KB API. 29 | * 30 | * For now, all {@link UnknownHostException}s and {@link IOException}s from 31 | * OpenCyc API will be wrapped with KbRuntimeException. This is because the 32 | * KB API user is not expected to handle such exceptions. 33 | * 34 | * @author Vijay Raj 35 | * @version $Id: KbRuntimeException.java 151668 2014-06-03 21:46:52Z jmoszko 36 | * $ 37 | */ 38 | public class KbRuntimeException extends RuntimeException { 39 | 40 | //====| Factory methods |=================================================================// 41 | 42 | /** 43 | * Converts a Throwable to a KbRuntimeException. If the Throwable is a 44 | * KbRuntimeException, it will be passed through unmodified; otherwise, it will be wrapped 45 | * in a new KbRuntimeException. 46 | * 47 | * @param cause the Throwable to convert 48 | * 49 | * @return a KbRuntimeException 50 | */ 51 | public static KbRuntimeException fromThrowable(Throwable cause) { 52 | return (cause instanceof KbRuntimeException) 53 | ? (KbRuntimeException) cause 54 | : new KbRuntimeException(cause); 55 | } 56 | 57 | /** 58 | * Converts a Throwable to a KbRuntimeException with the specified detail message. If the 59 | * Throwable is a KbRuntimeException and if the Throwable's message is identical to the 60 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 61 | * a new KbRuntimeException with the detail message. 62 | * 63 | * @param cause the Throwable to convert 64 | * @param message the specified detail message 65 | * 66 | * @return a KbRuntimeException 67 | */ 68 | public static KbRuntimeException fromThrowable(String message, Throwable cause) { 69 | return (cause instanceof KbRuntimeException && Objects.equals(message, cause.getMessage())) 70 | ? (KbRuntimeException) cause 71 | : new KbRuntimeException(message, cause); 72 | } 73 | 74 | //====| Construction |====================================================================// 75 | 76 | protected KbRuntimeException(Throwable cause) { 77 | super(cause); 78 | } 79 | 80 | public KbRuntimeException(String msg) { 81 | super(msg); 82 | } 83 | 84 | protected KbRuntimeException(String msg, Throwable cause) { 85 | super(msg, cause); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/KbServerSideException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: KbServerSideException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * Wraps all Cyc server errors, when a more specific semantic error can not be thrown. 28 | * 29 | * @author Vijay Raj 30 | * @version $Id: KbServerSideException.java 185299 2019-01-14 16:15:35Z daves $ 31 | */ 32 | public class KbServerSideException extends KbRuntimeException{ 33 | 34 | //====| Factory methods |=================================================================// 35 | 36 | /** 37 | * Converts a Throwable to a KbServerSideException. If the Throwable is a 38 | * KbServerSideException, it will be passed through unmodified; otherwise, it will be wrapped 39 | * in a new KbServerSideException. 40 | * 41 | * @param cause the Throwable to convert 42 | * 43 | * @return a KbServerSideException 44 | */ 45 | public static KbServerSideException fromThrowable(Throwable cause) { 46 | return (cause instanceof KbServerSideException) 47 | ? (KbServerSideException) cause 48 | : new KbServerSideException(cause); 49 | } 50 | 51 | /** 52 | * Converts a Throwable to a KbServerSideException with the specified detail message. If the 53 | * Throwable is a KbServerSideException and if the Throwable's message is identical to the 54 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 55 | * a new KbServerSideException with the detail message. 56 | * 57 | * @param cause the Throwable to convert 58 | * @param message the specified detail message 59 | * 60 | * @return a KbServerSideException 61 | */ 62 | public static KbServerSideException fromThrowable(String message, Throwable cause) { 63 | return (cause instanceof KbServerSideException && Objects.equals(message, cause.getMessage())) 64 | ? (KbServerSideException) cause 65 | : new KbServerSideException(message, cause); 66 | } 67 | 68 | //====| Construction |====================================================================// 69 | 70 | protected KbServerSideException(Throwable cause) { 71 | super(cause); 72 | } 73 | 74 | public KbServerSideException(String msg) { 75 | super(msg); 76 | } 77 | 78 | protected KbServerSideException(String msg, Throwable cause) { 79 | super(msg, cause); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/KbTypeConflictException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: KbTypeConflictException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | /** 26 | * Thrown when an entity exists in the KB, but is incompatible with a particular semantic object 27 | * type. The difference between this exception and {@link com.cyc.kb.exception.KbTypeException } is 28 | * that in this case, the KB entity cannot be turned into the expected type by addition of 29 | * assertions--instead, there is an existing assertion on the KB entity that specifically conflicts 30 | * with the desired type. In contrast, a KbTypeException signals that the KB entity is 31 | * not of the desired type, but does not signal that there is a conflict between some existing 32 | * assertion and the desired type. For a simple KbTypeException, it is possible that 33 | * simply adding more assertions will turn the KB entity into the desired type of entity. 34 | * 35 | * @author Nathan Winant 36 | * @version $Id: KbTypeConflictException.java 185299 2019-01-14 16:15:35Z daves $ 37 | */ 38 | public class KbTypeConflictException extends KbTypeException { 39 | 40 | //====| Factory methods |=================================================================// 41 | 42 | /** 43 | * Converts a Throwable to a KbTypeConflictException. If the Throwable is a 44 | * KbTypeConflictException, it will be passed through unmodified; otherwise, it will be wrapped 45 | * in a new KbTypeConflictException. 46 | * 47 | * @param cause the Throwable to convert 48 | * 49 | * @return a KbTypeConflictException 50 | */ 51 | public static KbTypeConflictException fromThrowable(Throwable cause) { 52 | return (cause instanceof KbTypeConflictException) 53 | ? (KbTypeConflictException) cause 54 | : new KbTypeConflictException(cause); 55 | } 56 | 57 | /** 58 | * Converts a Throwable to a KbTypeConflictException with the specified detail message. If the 59 | * Throwable is a KbTypeConflictException and if the Throwable's message is identical to the 60 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 61 | * a new KbTypeConflictException with the detail message. 62 | * 63 | * @param cause the Throwable to convert 64 | * @param message the specified detail message 65 | * 66 | * @return a KbTypeConflictException 67 | */ 68 | public static KbTypeConflictException fromThrowable(String message, Throwable cause) { 69 | return (cause instanceof KbTypeConflictException && Objects.equals(message, cause.getMessage())) 70 | ? (KbTypeConflictException) cause 71 | : new KbTypeConflictException(message, cause); 72 | } 73 | 74 | //====| Construction |====================================================================// 75 | 76 | protected KbTypeConflictException(Throwable cause) { 77 | super(cause); 78 | } 79 | 80 | public KbTypeConflictException(String msg) { 81 | super(msg); 82 | } 83 | 84 | protected KbTypeConflictException(String msg, Throwable cause) { 85 | super(msg, cause); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/KbTypeException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: KbTypeException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * Thrown when an entity exists in the KB, but does not currently meet the 28 | * requirements of a particular semantic object type. 29 | * 30 | * @author Nathan Winant 31 | * @version $Id: KbTypeException.java 185299 2019-01-14 16:15:35Z daves $ 32 | */ 33 | public class KbTypeException extends KbException { 34 | 35 | //====| Factory methods |=================================================================// 36 | 37 | /** 38 | * Converts a Throwable to a KbTypeException. If the Throwable is a 39 | * KbTypeException, it will be passed through unmodified; otherwise, it will be wrapped 40 | * in a new KbTypeException. 41 | * 42 | * @param cause the Throwable to convert 43 | * 44 | * @return a KbTypeException 45 | */ 46 | public static KbTypeException fromThrowable(Throwable cause) { 47 | return (cause instanceof KbTypeException) 48 | ? (KbTypeException) cause 49 | : new KbTypeException(cause); 50 | } 51 | 52 | /** 53 | * Converts a Throwable to a KbTypeException with the specified detail message. If the 54 | * Throwable is a KbTypeException and if the Throwable's message is identical to the 55 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 56 | * a new KbTypeException with the detail message. 57 | * 58 | * @param cause the Throwable to convert 59 | * @param message the specified detail message 60 | * 61 | * @return a KbTypeException 62 | */ 63 | public static KbTypeException fromThrowable(String message, Throwable cause) { 64 | return (cause instanceof KbTypeException && Objects.equals(message, cause.getMessage())) 65 | ? (KbTypeException) cause 66 | : new KbTypeException(message, cause); 67 | } 68 | 69 | //====| Construction |====================================================================// 70 | 71 | protected KbTypeException(Throwable cause) { 72 | super(cause); 73 | } 74 | 75 | public KbTypeException(String msg) { 76 | super(msg); 77 | } 78 | 79 | protected KbTypeException(String msg, Throwable cause) { 80 | super(msg, cause); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/StaleKbObjectException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | /* 4 | * #%L 5 | * File: StaleKbObjectException.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Assertion; 24 | import com.cyc.kb.KbObject; 25 | import com.cyc.kb.KbTerm; 26 | import com.cyc.kb.spi.KbService; 27 | import java.util.Objects; 28 | 29 | /** 30 | * Thrown when a stale {@link KbObject} is passed to a method. 31 | *

32 | * The KB API factory methods that find or create terms and assertions cache the KB Object they 33 | * return. Multiple get/findOrCreate requests to the same object will be return the identical 34 | * underlying object from the cache. The cache can be cleared using {@link KbService#clearCache()}, 35 | * which can be called like so: {@code Cyc.getKbService().clearCache(); } 36 | *

37 | * When an object is deleted using {@link Assertion#delete()} or {@link KbTerm#delete()}, the object 38 | * is marked "invalid". The validity of the object can be checked using {@link Assertion#isValid()} 39 | * or {@link KbTerm#isValid()}, respectively. 40 | * 41 | * @author Vijay Raj 42 | * @version $Id: StaleKbObjectException.java 151668 2014-06-03 21:46:52Z jmoszko 43 | * $ 44 | */ 45 | public class StaleKbObjectException extends KbRuntimeException { 46 | 47 | //====| Factory methods |=================================================================// 48 | 49 | /** 50 | * Converts a Throwable to a StaleKbObjectException. If the Throwable is a 51 | * StaleKbObjectException, it will be passed through unmodified; otherwise, it will be wrapped 52 | * in a new StaleKbObjectException. 53 | * 54 | * @param cause the Throwable to convert 55 | * 56 | * @return a StaleKbObjectException 57 | */ 58 | public static StaleKbObjectException fromThrowable(Throwable cause) { 59 | return (cause instanceof StaleKbObjectException) 60 | ? (StaleKbObjectException) cause 61 | : new StaleKbObjectException(cause); 62 | } 63 | 64 | /** 65 | * Converts a Throwable to a StaleKbObjectException with the specified detail message. If the 66 | * Throwable is a StaleKbObjectException and if the Throwable's message is identical to the 67 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 68 | * a new StaleKbObjectException with the detail message. 69 | * 70 | * @param cause the Throwable to convert 71 | * @param message the specified detail message 72 | * 73 | * @return a StaleKbObjectException 74 | */ 75 | public static StaleKbObjectException fromThrowable(String message, Throwable cause) { 76 | return (cause instanceof StaleKbObjectException && Objects.equals(message, cause.getMessage())) 77 | ? (StaleKbObjectException) cause 78 | : new StaleKbObjectException(message, cause); 79 | } 80 | 81 | //====| Construction |====================================================================// 82 | 83 | public StaleKbObjectException(String msg) { 84 | super(msg); 85 | } 86 | 87 | protected StaleKbObjectException(Throwable cause) { 88 | super(cause); 89 | } 90 | 91 | protected StaleKbObjectException(String msg, Throwable cause) { 92 | super(msg, cause); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/VariableArityException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.exception; 2 | 3 | /* 4 | * #%L 5 | * File: VariableArityException.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Relation; 24 | import java.util.Objects; 25 | 26 | /** 27 | * Thrown when the arity of a Relation without a fixed arity is requested. For 28 | * variable-arity relations, {@link Relation#getArityMin()} and 29 | * {@link Relation#getArityMax()} methods should be used. 30 | * 31 | * @author Dave Schneider 32 | * @version $Id: VariableArityException.java 151668 2014-06-03 21:46:52Z jmoszko 33 | * $ 34 | */ 35 | public class VariableArityException extends KbRuntimeException { 36 | 37 | //====| Factory methods |=================================================================// 38 | 39 | /** 40 | * Converts a Throwable to a VariableArityException with the specified detail message. If the 41 | * Throwable is a VariableArityException and if the Throwable's message is identical to the 42 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 43 | * a new VariableArityException with the detail message. 44 | * 45 | * @param cause the Throwable to convert 46 | * @param message the specified detail message 47 | * 48 | * @return a VariableArityException 49 | */ 50 | public static VariableArityException fromThrowable(String message, Throwable cause) { 51 | return (cause instanceof VariableArityException && Objects.equals(message, cause.getMessage())) 52 | ? (VariableArityException) cause 53 | : new VariableArityException(message, cause); 54 | } 55 | 56 | //====| Construction |====================================================================// 57 | 58 | public VariableArityException(String message) { 59 | super(message); 60 | } 61 | 62 | protected VariableArityException(String message, Throwable cause) { 63 | super(message, cause); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * KB API exception hierarchy. 3 | * 4 | * {@link com.cyc.kb.exception.KbException} is the root level exception for KB API. All other 5 | * exceptions thrown by the API are sub-classes of this. 6 | * 7 | * {@link com.cyc.kb.exception.StaleKbObjectException} is thrown when the Java program uses 8 | * an object reference that points to a KB concept that has been deleted, by calling the API 9 | * delete method. 10 | * 11 | * {@link com.cyc.kb.exception.KbRuntimeException} is thrown mostly wrapping any lower-level 12 | * connection exceptions. 13 | * 14 | * Refer to individual exception documentation for more details. 15 | */ 16 | package com.cyc.kb.exception; 17 | 18 | /* 19 | * #%L 20 | * File: package-info.java 21 | * Project: Core API 22 | * %% 23 | * Copyright (C) 2015 - 2019 Cycorp, Inc 24 | * %% 25 | * Licensed under the Apache License, Version 2.0 (the "License"); 26 | * you may not use this file except in compliance with the License. 27 | * You may obtain a copy of the License at 28 | * 29 | * http://www.apache.org/licenses/LICENSE-2.0 30 | * 31 | * Unless required by applicable law or agreed to in writing, software 32 | * distributed under the License is distributed on an "AS IS" BASIS, 33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 34 | * See the License for the specific language governing permissions and 35 | * limitations under the License. 36 | * #L% 37 | */ 38 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Interfaces for manipulating CycL-based java objects, both for the purpose of 3 | * making assertions and for retrieving terms and values via simple queries. 4 | * 5 | *

6 | * Because methods accessing a Cyc server may not return instantaneously, developers are strongly 7 | * advised to avoid using KB API methods inside AWT threads (or any threads on which a UI is 8 | * critically dependent). 9 | * 10 | *

11 | * The underlying API throws IOException and UnknownHostExeception to indicate some arbitrary IO 12 | * issue and Cyc server not being at the specified location respectively. In the KB API both of 13 | * these exceptions are wrapped inside a KbRuntimeException throughout the API and the cause field 14 | * is set appropriately. 15 | * 16 | *

17 | * The main uses of the KB API fall into two broad categories: (a) making terms and assertions, and 18 | * (b) running queries. You may get terms, assertions, and queries via the static {@code #get(...)} 19 | * and {@code #findOrCreate(...)} factory methods on the interfaces themselves; sub-classes also 20 | * have such factory methods. These factory methods will retrieve the relevant object from the KB, 21 | * and can be set to create the object on the Cyc server if it doesn't already exist on the server. 22 | * E.g.: 23 | *

24 | *

25 |  * Context.get("SomeMt");
26 |  * 
27 |  * KbTerm.findOrCreate("SomeTerm");
28 |  * 
29 |  * Sentence.get(predicate, arg1, arg2);
30 |  * 
31 |  * Assertion.get("someassertionid");
32 |  * 
33 |  * Query.get(sentence, context);
34 |  * 
35 | *

36 | * Once the objects exists, the {@code #get(...)} and {@code #findOrCreate(...)} methods on 37 | * {@link com.cyc.kb.Assertion}, {@link com.cyc.kb.Fact}, and {@link com.cyc.kb.Rule} can be used to 38 | * create the actual assertions. The KB API generally allows the creation and retrieval of Cyc KB 39 | * objects (KbIndividuals, KbCollections, Facts, etc.) from a variety of forms including their 40 | * string representations, their IDs, and from the objects that will comprise them. The string-based 41 | * factory methods in Assertion and its sub-class factories are a convenient way to 42 | * create assertions without needing to first create the KbCollection and 43 | * KbIndividual objects, but they do require correct syntax, and the terms must already 44 | * exist on the Cyc server. 45 | * 46 | *

47 | * The API provides many methods that take Strings as inputs. This leads to most methods having 48 | * CreateException and KbTypeException. To limit the types of exceptions in method signatures, we 49 | * wrap them in IllegalArgumentException. This is done only to the methods where the focus is not 50 | * the creation of a new term. 51 | * 52 | *

53 | * All factory methods throw exceptions as {@link com.cyc.kb.exception.CreateException}, 54 | * {@link com.cyc.kb.exception.KbTypeException}, or a subclass of those exceptions. 55 | * 56 | *

57 | * In many cases, the KB API includes methods that specify a context and similar methods that don't 58 | * require a context parameter. Default contexts for asserting and querying can be set on a 59 | * thread-by-thread basis using 60 | * {@link com.cyc.session.SessionOptions#setDefaultContext(com.cyc.kb.DefaultContext)}. 61 | */ 62 | package com.cyc.kb; 63 | 64 | /* 65 | * #%L 66 | * File: package-info.java 67 | * Project: Core API 68 | * %% 69 | * Copyright (C) 2015 - 2019 Cycorp, Inc 70 | * %% 71 | * Licensed under the Apache License, Version 2.0 (the "License"); 72 | * you may not use this file except in compliance with the License. 73 | * You may obtain a copy of the License at 74 | * 75 | * http://www.apache.org/licenses/LICENSE-2.0 76 | * 77 | * Unless required by applicable law or agreed to in writing, software 78 | * distributed under the License is distributed on an "AS IS" BASIS, 79 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 80 | * See the License for the specific language governing permissions and 81 | * limitations under the License. 82 | * #L% 83 | */ 84 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/spi/KbApiService.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.spi; 2 | 3 | /* 4 | * #%L 5 | * File: KbApiService.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.CycApiEntryPoint; 24 | 25 | /** 26 | * The primary entrypoint for a KB API implementation. 27 | * 28 | * @author nwinant 29 | */ 30 | public interface KbApiService extends CycApiEntryPoint { 31 | 32 | AssertionService getAssertionService(); 33 | 34 | BinaryPredicateService getBinaryPredicateService(); 35 | 36 | ContextService getContextService(); 37 | 38 | FactService getFactService(); 39 | 40 | FirstOrderCollectionService getFirstOrderCollectionService(); 41 | 42 | KbCollectionService getKbCollectionService(); 43 | 44 | KbFunctionService getKbFunctionService(); 45 | 46 | KbIndividualService getKbIndividualService(); 47 | 48 | KbPredicateService getKbPredicateService(); 49 | 50 | KbService getKbService(); // TODO: rename and/or reorganize? - nwinant, 2017-10-16 51 | 52 | KbTermService getKbTermService(); 53 | 54 | RelationService getRelationService(); 55 | 56 | RuleService getRuleService(); 57 | 58 | SecondOrderCollectionService getSecondOrderCollectionService(); 59 | 60 | SentenceService getSentenceService(); 61 | 62 | SymbolService getSymbolService(); 63 | 64 | VariableService getVariableService(); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/spi/SymbolService.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.spi; 2 | 3 | /* 4 | * #%L 5 | * File: SymbolService.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Symbol; 24 | import com.cyc.kb.exception.KbTypeException; 25 | 26 | /** 27 | * Provides implementations of {@link com.cyc.kb.Symbol}. 28 | * 29 | * @author nwinant 30 | */ 31 | public interface SymbolService { 32 | 33 | /** 34 | * Creates an instance of #$CycLSubLSymbol represented by symStr in the underlying KB. 35 | * 36 | * @param symStr the string representing an #$CycLSubLSymbol in the KB 37 | * 38 | * @return the Symbol representing an #$CycLSubLSymbol in the KB 39 | * 40 | * @throws KbTypeException Symbols are created on demand and are not expected to throw any 41 | * exception 42 | */ 43 | Symbol get(String symStr) throws KbTypeException; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/spi/VariableService.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.spi; 2 | 3 | /* 4 | * #%L 5 | * File: VariableService.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Variable; 24 | import com.cyc.kb.exception.KbTypeException; 25 | 26 | /** 27 | * Provides implementations of {@link com.cyc.kb.Variable}. 28 | * 29 | * @author nwinant 30 | */ 31 | public interface VariableService { 32 | 33 | /** 34 | * Creates an instance of #$CycLVariable represented by varStr in the underlying KB. 35 | * 36 | * @param varStr the string representing an #$CycLVariable in the KB 37 | * 38 | * @return the Variable representing an #$CycLVariable in the KB 39 | * 40 | * @throws KbTypeException if the term represented by varStr is not an instance of #$CycLVariable 41 | * and cannot be made into one. 42 | * 43 | * Symbols are created on demand and are not expected to throw any exception 44 | */ 45 | Variable get(String varStr) throws KbTypeException; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All KB API service provider interfaces. 3 | */ 4 | package com.cyc.kb.spi; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/BinaryPredicateWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: BinaryPredicateWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.BinaryPredicate; 24 | import com.cyc.kb.Context; 25 | import com.cyc.kb.Fact; 26 | import com.cyc.kb.exception.CreateException; 27 | import com.cyc.kb.exception.KbTypeException; 28 | import java.util.Collection; 29 | 30 | /** 31 | * An abstract base class for implementing BinaryPredicates per the decorator pattern. To use, 32 | * extend this class and implement the {@link #wrapped() } method to return the wrapped object. 33 | * 34 | * @author nwinant 35 | */ 36 | public abstract class BinaryPredicateWrapper extends KbPredicateWrapper implements BinaryPredicate { 37 | 38 | //====| Abstract methods |================================================================// 39 | 40 | @Override 41 | protected abstract BinaryPredicate wrapped(); 42 | 43 | //====| Public methods |==================================================================// 44 | 45 | @Override 46 | public Fact addFact(Context ctx, Object arg1, Object arg2) 47 | throws KbTypeException, CreateException { 48 | return wrapped().addFact(ctx, arg1, arg2); 49 | } 50 | 51 | @Override 52 | public Collection getValuesForArg(Object arg1, Object arg2, Context ctx) { 53 | return wrapped().getValuesForArg(arg1, arg2, ctx); 54 | } 55 | 56 | @Override 57 | public Collection getValuesForArg(Object arg1, Object arg2) { 58 | return wrapped().getValuesForArg(arg1, arg2); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/ContextWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: ContextWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Context; 24 | import com.cyc.kb.exception.CreateException; 25 | import com.cyc.kb.exception.KbTypeException; 26 | import java.util.Collection; 27 | 28 | /** 29 | * An abstract base class for implementing Contexts per the decorator pattern. To use, extend this 30 | * class and implement the {@link #wrapped() } method to return the wrapped object. 31 | * 32 | * @author nwinant 33 | */ 34 | public abstract class ContextWrapper extends KbIndividualWrapper implements Context { 35 | 36 | //====| Abstract methods |================================================================// 37 | 38 | @Override 39 | protected abstract Context wrapped(); 40 | 41 | //====| Public methods |==================================================================// 42 | 43 | @Override 44 | public Collection getExtensions() { 45 | return wrapped().getExtensions(); 46 | } 47 | /* 48 | @Override 49 | public Context addExtension(String moreSpecificStr) throws KbTypeException, CreateException { 50 | return wrapped().addExtension(moreSpecificStr); 51 | } 52 | */ 53 | @Override 54 | public Context addExtension(Context moreSpecific) throws KbTypeException, CreateException { 55 | return wrapped().addExtension(moreSpecific); 56 | } 57 | 58 | @Override 59 | public Collection getInheritsFrom() { 60 | return wrapped().getInheritsFrom(); 61 | } 62 | /* 63 | @Override 64 | public Context addInheritsFrom(String moreGeneralStr) throws KbTypeException, CreateException { 65 | return wrapped().addInheritsFrom(moreGeneralStr); 66 | } 67 | */ 68 | @Override 69 | public Context addInheritsFrom(Context moreGeneral) throws KbTypeException, CreateException { 70 | return wrapped().addInheritsFrom(moreGeneral); 71 | } 72 | 73 | @Override 74 | public Context getMonad() { 75 | return wrapped().getMonad(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/FactWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: FactWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Fact; 24 | 25 | /** 26 | * An abstract base class for implementing Facts per the decorator pattern. To use, extend this 27 | * class and implement the {@link #wrapped() } method to return the wrapped object. 28 | * 29 | * @author nwinant 30 | */ 31 | public abstract class FactWrapper extends AssertionWrapper implements Fact { 32 | 33 | //====| Abstract methods |================================================================// 34 | 35 | @Override 36 | protected abstract Fact wrapped(); 37 | 38 | //====| Public methods |==================================================================// 39 | 40 | } 41 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/FirstOrderCollectionWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: FirstOrderCollectionWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Context; 24 | import com.cyc.kb.FirstOrderCollection; 25 | import com.cyc.kb.KbCollection; 26 | import com.cyc.kb.exception.CreateException; 27 | import com.cyc.kb.exception.KbTypeException; 28 | import java.util.Collection; 29 | 30 | /** 31 | * An abstract base class for implementing FirstOrderCollections per the decorator pattern. To use, 32 | * extend this class and implement the {@link #wrapped() } method to return the wrapped object. 33 | * 34 | * @author nwinant 35 | */ 36 | public abstract class FirstOrderCollectionWrapper 37 | extends KbCollectionWrapper 38 | implements FirstOrderCollection { 39 | 40 | //====| Abstract methods |================================================================// 41 | 42 | @Override 43 | protected abstract FirstOrderCollection wrapped(); 44 | 45 | //====| Public methods |==================================================================// 46 | 47 | @Override 48 | public Collection getGeneralizations() { 49 | return wrapped().getGeneralizations(); 50 | } 51 | 52 | @Override 53 | public Collection getGeneralizations(Context ctx) { 54 | return wrapped().getGeneralizations(ctx); 55 | } 56 | 57 | @Override 58 | public FirstOrderCollection addGeneralization(KbCollection moreGeneral, Context ctx) 59 | throws KbTypeException, CreateException { 60 | return wrapped().addGeneralization(moreGeneral, ctx); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/KbFunctionWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: KbFunctionWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Context; 24 | import com.cyc.kb.KbCollection; 25 | import com.cyc.kb.KbFunction; 26 | import com.cyc.kb.KbObject; 27 | import com.cyc.kb.exception.CreateException; 28 | import com.cyc.kb.exception.KbException; 29 | import com.cyc.kb.exception.KbTypeException; 30 | import java.util.Collection; 31 | 32 | /** 33 | * An abstract base class for implementing KbFunctions per the decorator pattern. To use, extend this 34 | * class and implement the {@link #wrapped() } method to return the wrapped object. 35 | * 36 | * @author nwinant 37 | */ 38 | public abstract class KbFunctionWrapper extends RelationWrapper implements KbFunction { 39 | 40 | //====| Abstract methods |================================================================// 41 | 42 | @Override 43 | protected abstract KbFunction wrapped(); 44 | 45 | //====| Public methods |==================================================================// 46 | 47 | @Override 48 | public O findOrCreateFunctionalTerm(Class retType, Object... args) 49 | throws KbTypeException, CreateException { 50 | return wrapped().findOrCreateFunctionalTerm(retType, args); 51 | } 52 | 53 | @Override 54 | public Collection getResultIsa() { 55 | return wrapped().getResultIsa(); 56 | } 57 | 58 | @Override 59 | public Collection getResultIsa(Context ctx) { 60 | return wrapped().getResultIsa(ctx); 61 | } 62 | 63 | @Override 64 | public KbFunction addResultIsa(KbCollection col, Context ctx) 65 | throws KbTypeException, CreateException { 66 | return wrapped().addResultIsa(col, ctx); 67 | } 68 | 69 | @Override 70 | public Collection getResultGenl() throws KbException { 71 | return wrapped().getResultGenl(); 72 | } 73 | 74 | @Override 75 | public Collection getResultGenl(Context ctx) { 76 | return wrapped().getResultGenl(ctx); 77 | } 78 | 79 | @Override 80 | public KbFunction addResultGenl(KbCollection col, Context ctx) 81 | throws KbTypeException, CreateException { 82 | return wrapped().addResultGenl(col, ctx); 83 | } 84 | 85 | @Override 86 | public boolean isUnreifiable() { 87 | return wrapped().isUnreifiable(); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/KbIndividualWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: KbIndividualWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Context; 24 | import com.cyc.kb.KbCollection; 25 | import com.cyc.kb.KbIndividual; 26 | import java.util.Collection; 27 | 28 | /** 29 | * An abstract base class for implementing KbIndividuals per the decorator pattern. To use, extend 30 | * this class and implement the {@link #wrapped() } method to return the wrapped object. 31 | * 32 | * @author nwinant 33 | */ 34 | public abstract class KbIndividualWrapper extends KbTermWrapper implements KbIndividual { 35 | 36 | //====| Abstract methods |================================================================// 37 | 38 | @Override 39 | protected abstract KbIndividual wrapped(); 40 | 41 | //====| Public methods |==================================================================// 42 | 43 | @Override 44 | public Collection instanceOf() { 45 | return wrapped().instanceOf(); 46 | } 47 | /* 48 | @Override 49 | public Collection instanceOf(String ctxStr) { 50 | return wrapped().instanceOf(); 51 | } 52 | */ 53 | @Override 54 | public Collection instanceOf(Context ctx) { 55 | return wrapped().instanceOf(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/RuleWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: RuleWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Rule; 24 | import com.cyc.kb.Sentence; 25 | 26 | /** 27 | * An abstract base class for implementing Rules per the decorator pattern. To use, extend this 28 | * class and implement the {@link #wrapped() } method to return the wrapped object. 29 | * 30 | * @author nwinant 31 | */ 32 | public abstract class RuleWrapper extends AssertionWrapper implements Rule { 33 | 34 | //====| Abstract methods |================================================================// 35 | 36 | @Override 37 | protected abstract Rule wrapped(); 38 | 39 | //====| Public methods |==================================================================// 40 | 41 | @Override 42 | public Sentence getAntecedent() { 43 | return wrapped().getAntecedent(); 44 | } 45 | 46 | @Override 47 | public Sentence getConsequent() { 48 | return wrapped().getConsequent(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/SecondOrderCollectionWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: SecondOrderCollectionWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.SecondOrderCollection; 24 | 25 | /** 26 | * An abstract base class for implementing SecondOrderCollections per the decorator pattern. To use, 27 | * extend this class and implement the {@link #wrapped() } method to return the wrapped object. 28 | * 29 | * @author nwinant 30 | */ 31 | public abstract class SecondOrderCollectionWrapper 32 | extends KbCollectionWrapper 33 | implements SecondOrderCollection { 34 | 35 | //====| Abstract methods |================================================================// 36 | 37 | @Override 38 | protected abstract SecondOrderCollection wrapped(); 39 | 40 | //====| Public methods |==================================================================// 41 | 42 | } 43 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/SymbolWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: SymbolWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Symbol; 24 | 25 | /** 26 | * An abstract base class for implementing Symbols per the decorator pattern. To use, extend this 27 | * class and implement the {@link #wrapped() } method to return the wrapped object. 28 | * 29 | * @author nwinant 30 | */ 31 | public abstract class SymbolWrapper extends KbObjectWrapper implements Symbol { 32 | 33 | //====| Abstract methods |================================================================// 34 | 35 | @Override 36 | protected abstract Symbol wrapped(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/VariableWrapper.java: -------------------------------------------------------------------------------- 1 | package com.cyc.kb.wrapper; 2 | 3 | /* 4 | * #%L 5 | * File: VariableWrapper.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Variable; 24 | 25 | /** 26 | * An abstract base class for implementing Variables per the decorator pattern. To use, extend this 27 | * class and implement the {@link #wrapped() } method to return the wrapped object. 28 | * 29 | * @author nwinant 30 | */ 31 | public abstract class VariableWrapper extends KbObjectWrapper implements Variable { 32 | 33 | //====| Abstract methods |================================================================// 34 | 35 | @Override 36 | protected abstract Variable wrapped(); 37 | 38 | //====| Public methods |==================================================================// 39 | 40 | @Override 41 | public String getName() { 42 | return wrapped().getName(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/kb/wrapper/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Abstract classes for implementing KbObjects per the decorator pattern. 3 | */ 4 | package com.cyc.kb.wrapper; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/nl/GenerationMode.java: -------------------------------------------------------------------------------- 1 | package com.cyc.nl; 2 | 3 | /* 4 | * #%L 5 | * File: GenerationMode.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | import com.cyc.kb.Symbol; 25 | 26 | /** 27 | * 28 | * @author daves 29 | */ 30 | public interface GenerationMode { 31 | Symbol toSymbol(); 32 | } 33 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/nl/HtmlLinkType.java: -------------------------------------------------------------------------------- 1 | package com.cyc.nl; 2 | 3 | /* 4 | * #%L 5 | * File: HtmlLinkType.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | /** 24 | * 25 | * @author daves 26 | */ 27 | public enum HtmlLinkType { 28 | 29 | DEFAULT(":DEFAULT"), 30 | CYC_BROWSER(":CYC-BROWSER"), 31 | NONE(":NONE"); 32 | 33 | private final String name; 34 | 35 | private HtmlLinkType(String name) { 36 | this.name = name; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return name; 42 | } 43 | 44 | public static HtmlLinkType fromValue(String string) { 45 | for (HtmlLinkType type : HtmlLinkType.values()) { 46 | if (string.equals(type.name)) { 47 | return type; 48 | } 49 | } 50 | return HtmlLinkType.valueOf(string); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/nl/NlForce.java: -------------------------------------------------------------------------------- 1 | package com.cyc.nl; 2 | 3 | /* 4 | * #%L 5 | * File: NlForce.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | import com.cyc.kb.Symbol; 25 | 26 | /** 27 | * 28 | * @author daves 29 | */ 30 | public interface NlForce { 31 | Symbol toSymbol(); 32 | } 33 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/nl/Paraphrase.java: -------------------------------------------------------------------------------- 1 | package com.cyc.nl; 2 | 3 | import java.util.List; 4 | 5 | /* 6 | * #%L 7 | * File: Paraphrase.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * A class that bundles information about the rendering of a term in a natural language. 28 | * 29 | * @author baxter 30 | * @param The CycL we're paraphrasing. 31 | */ 32 | public interface Paraphrase extends Comparable> { 33 | 34 | 35 | @Override 36 | public boolean equals(Object obj); 37 | 38 | @Override 39 | public int hashCode(); 40 | 41 | @Override 42 | public int compareTo(Paraphrase object); 43 | 44 | /** 45 | * Returns the NL string paraphrasing the term. 46 | * 47 | * @return the NL string paraphrasing the term. 48 | */ 49 | public String getString(); 50 | 51 | @Override 52 | public String toString(); 53 | 54 | /** 55 | * Returns the CycL term of which this is a paraphrase. 56 | * 57 | * @return the CycL term of which this is a paraphrase. 58 | */ 59 | public C getCycl(); 60 | 61 | /** 62 | * 63 | * @param sub 64 | * @return this Paraphrase object. 65 | */ 66 | public Paraphrase addSubParaphrase(SubParaphrase sub); 67 | 68 | public List getSubParaphrases (); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/nl/SubParaphrase.java: -------------------------------------------------------------------------------- 1 | package com.cyc.nl; 2 | 3 | /* 4 | * #%L 5 | * File: SubParaphrase.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | import com.cyc.kb.ArgPosition; 25 | 26 | /** 27 | * 28 | * @author daves 29 | */ 30 | public interface SubParaphrase extends Paraphrase { 31 | 32 | /** 33 | * Returns the arg position of the term paraphrased in its parent formula. 34 | * @return the arg position of the term paraphrased in its parent formula. 35 | */ 36 | ArgPosition getArgPosition(); 37 | 38 | /** 39 | * Returns the parent paraphrase of this sub-paraphrase. 40 | * @return the parent paraphrase of this sub-paraphrase. 41 | */ 42 | Paraphrase getParentParaphrase(); 43 | 44 | /** 45 | * Returns the start index of this paraphrase within its parent. 46 | * @return the start index of this paraphrase within its parent. 47 | */ 48 | int getStartIndex(); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/nl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides support for the NL API, which translates back and forth between CycL and natural 3 | * language. 4 | */ 5 | package com.cyc.nl; 6 | 7 | /* 8 | * #%L 9 | * File: package-info.java 10 | * Project: Core API 11 | * %% 12 | * Copyright (C) 2015 - 2019 Cycorp, Inc 13 | * %% 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * #L% 26 | */ 27 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/nl/spi/NlApiService.java: -------------------------------------------------------------------------------- 1 | package com.cyc.nl.spi; 2 | 3 | /* 4 | * #%L 5 | * File: NlApiService.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.CycApiEntryPoint; 24 | 25 | /** 26 | * The primary entrypoint for an NL API implementation. 27 | * 28 | * @author nwinant 29 | */ 30 | public interface NlApiService extends CycApiEntryPoint { 31 | 32 | ParaphraserFactory getParaphraserFactory(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/nl/spi/ParaphraserFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cycorp, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.cyc.nl.spi; 17 | 18 | /* 19 | * #%L 20 | * File: ParaphraserFactory.java 21 | * Project: Core API 22 | * %% 23 | * Copyright (C) 2015 - 2019 Cycorp, Inc 24 | * %% 25 | * Licensed under the Apache License, Version 2.0 (the "License"); 26 | * you may not use this file except in compliance with the License. 27 | * You may obtain a copy of the License at 28 | * 29 | * http://www.apache.org/licenses/LICENSE-2.0 30 | * 31 | * Unless required by applicable law or agreed to in writing, software 32 | * distributed under the License is distributed on an "AS IS" BASIS, 33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 34 | * See the License for the specific language governing permissions and 35 | * limitations under the License. 36 | * #L% 37 | */ 38 | 39 | import com.cyc.nl.Paraphraser; 40 | import com.cyc.nl.Paraphraser.ParaphrasableType; 41 | 42 | /** 43 | * 44 | * @author nwinant 45 | */ 46 | public interface ParaphraserFactory { 47 | 48 | Paraphraser getParaphraser(ParaphrasableType type); 49 | 50 | boolean isBasicParaphraser(Paraphraser paraphraser); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/nl/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All NL API service provider interfaces. 3 | */ 4 | package com.cyc.nl.spi; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Cyc API factories and constants. 3 | */ 4 | package com.cyc; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/InferenceAnswerIdentifier.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | import com.cyc.session.CycSession; 4 | 5 | /* 6 | * #%L 7 | * File: InferenceAnswerIdentifier.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | //// Internal Imports 27 | //// External Imports 28 | /** 29 | *

InferenceAnswerIdentifier is designed to... 30 | * 31 | * @author jmoszko, May 13, 2014, 5:54:59 PM 32 | * @version $Id: InferenceAnswerIdentifier.java 185299 2019-01-14 16:15:35Z daves $ 33 | */ 34 | public interface InferenceAnswerIdentifier { 35 | 36 | int getAnswerId(); 37 | 38 | InferenceIdentifier getInferenceIdentifier(); 39 | 40 | CycSession getSession(); 41 | 42 | String stringApiValue(); 43 | 44 | Object cycListApiValue(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/InferenceIdentifier.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | import com.cyc.session.CycSession; 4 | 5 | /* 6 | * #%L 7 | * File: InferenceIdentifier.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * 28 | * @author nwinant 29 | */ 30 | public interface InferenceIdentifier { 31 | 32 | void close(); 33 | 34 | Integer getFirstProofId(Integer answerId); 35 | 36 | int getInferenceId(); 37 | 38 | int getProblemStoreId(); 39 | 40 | /** 41 | * Interrupt this inference. 42 | * 43 | * @param patience Give inference process this many seconds to halt gracefully, 44 | * after which terminate it with prejudice. A null value indicates infinite patience. 45 | */ 46 | void interrupt(final Integer patience); 47 | 48 | String stringApiValue(); 49 | 50 | CycSession getSession(); 51 | } 52 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/InferenceStatus.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | import com.cyc.query.parameters.InferenceParameterValue; 4 | 5 | /* 6 | * #%L 7 | * File: InferenceStatus.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | 27 | /** 28 | * 29 | * @author nwinant 30 | */ 31 | //@todo this doesn't really implement parameter-value, but it's something very similar 32 | public enum InferenceStatus implements InferenceParameterValue { 33 | 34 | /** 35 | * Newly created, attached to a problem store, query & mt unspecified. 36 | */ 37 | NEW, 38 | 39 | /** 40 | * Query & mt specified, resource constraints still unspecified. 41 | */ 42 | PREPARED, 43 | 44 | /** 45 | * Resource constraints specified, ready to start running under those constraints. 46 | */ 47 | READY, 48 | 49 | /** 50 | * The inference has not yet been run. 51 | */ 52 | NOT_STARTED, 53 | 54 | /** 55 | * The inference has been told to start, but may not actually be running yet. 56 | */ 57 | STARTED, 58 | 59 | /** 60 | * Currently in the act of performing inference. 61 | */ 62 | RUNNING, 63 | 64 | /** 65 | * Inference has been suspended, but may be possible to continue. 66 | */ 67 | SUSPENDED, 68 | 69 | /** 70 | * Inference was explicitly destroyed; answers & problems cannot be accessed. 71 | */ 72 | DEAD, 73 | 74 | /** 75 | * The query itself is a tautology, and therefore no inference will be performed on it. 76 | */ 77 | TAUTOLOGY, 78 | 79 | /** 80 | * The query contains an internal contradiction, and cannot be run. 81 | */ 82 | CONTRADICTION, 83 | 84 | /** 85 | * The query is syntactically ill-formed and cannot be run. 86 | */ 87 | ILL_FORMED; 88 | 89 | 90 | // Public 91 | /** 92 | * Does this status indicates that an inference may be currently available for this query? 93 | * 94 | * @return true if has been run, or is currently running, and the inference has not been 95 | * destroyed. 96 | */ 97 | public boolean indicatesInferenceExists() { 98 | return this.equals(STARTED) 99 | //|| this.equals(NEW) 100 | || this.equals(RUNNING) 101 | || this.equals(SUSPENDED); 102 | } 103 | 104 | /** 105 | * Does this status indicate that the inference is done? It may be continuable, but no further 106 | * work will be performed on it until instructed. 107 | * 108 | * @return true iff this status indicates that the inference is done. 109 | */ 110 | boolean indicatesDone() { 111 | return this.equals(SUSPENDED) 112 | || this.equals(DEAD); 113 | } 114 | 115 | /** 116 | * Does this status indicate that there is a problem with the query, such that an inference cannot 117 | * be run? 118 | * 119 | * @return true iff this status indicates that the query cannot be run. 120 | */ 121 | boolean indicatesQueryError() { 122 | return this.equals(TAUTOLOGY) 123 | || this.equals(CONTRADICTION) 124 | || this.equals(ILL_FORMED); 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/InferenceSuspendReason.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceSuspendReason.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * 26 | * @author nwinant 27 | */ 28 | public interface InferenceSuspendReason { 29 | 30 | /** Can an inference suspended for this reason be reset? */ 31 | boolean allowReset(); 32 | 33 | /** Can an inference suspended for this reason be stopped? */ 34 | boolean allowStop(); 35 | 36 | /** A string to describe the status of the inference. */ 37 | String getInferenceStatusString(); 38 | 39 | /** Can an inference suspended for this reason be continued? */ 40 | boolean isContinuable(); 41 | 42 | /** Was inference suspended because of an error? */ 43 | boolean isError(); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/ParaphrasedQueryAnswer.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: ParaphrasedQueryAnswer.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Variable; 24 | import com.cyc.nl.Paraphrase; 25 | import com.cyc.nl.Paraphraser; 26 | import java.util.Map; 27 | 28 | /** 29 | * 30 | * @author daves 31 | */ 32 | public interface ParaphrasedQueryAnswer extends QueryAnswer { 33 | 34 | public Paraphraser getParaphraser(); 35 | 36 | public Paraphrase getBindingParaphrase(Variable var); 37 | 38 | public Map getParaphrasedBindings(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/ProofIdentifier.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | import com.cyc.session.CycSession; 4 | 5 | /* 6 | * #%L 7 | * File: ProofIdentifier.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * 28 | * @author nwinant 29 | */ 30 | public interface ProofIdentifier { 31 | 32 | int getProofId(); 33 | 34 | int getInferenceId(); 35 | 36 | int getProblemStoreId(); 37 | 38 | InferenceIdentifier getInferenceIdentifier(); 39 | 40 | String stringApiValue(); 41 | 42 | CycSession getSession(); 43 | } 44 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/ProofView.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: ProofView.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.Cyc; 24 | import java.util.ArrayDeque; 25 | import java.util.Deque; 26 | import java.util.Iterator; 27 | import java.util.List; 28 | 29 | /** 30 | * An explanation for a specific answer to a query, expressed as a tree of {@link ProofViewNode}s. 31 | * In general they are intended to be rendered in an interactive display, with CycL and/or NL 32 | * (encoded in HTML) for nodes, and with their children displayed or hidden according to user 33 | * actions or preferences. 34 | * 35 | *

36 | * A ProofView instance is also a ProofViewNode, and serves as the root of 37 | * the tree. A suggested rendering algorithm would be to display this node, and recurse on all child 38 | * nodes for whom {@link ProofViewNode#isExpandInitially()} returns true. 39 | * 40 | * @author daves 41 | */ 42 | public interface ProofView extends ProofViewNode, QueryAnswerExplanation { 43 | 44 | //====| Factory methods |=================================================================// 45 | 46 | /** 47 | * Returns a ProofView for an answer, generating one if necessary via a call to 48 | * {@link ProofViewGenerator#generate()}. 49 | * 50 | * @param answer the answer for which to generate a ProofView. 51 | * @param spec the configuration parameters for ProofView generation. 52 | * 53 | * @return a ProofView. 54 | */ 55 | public static ProofView getProofView(QueryAnswer answer, ProofViewSpecification spec) { 56 | return Cyc.getProofViewService().getExplanation(answer, spec); 57 | } 58 | 59 | //====| Methods |=========================================================================// 60 | 61 | default Iterator toDepthFirstIterator() { 62 | final Deque queue = new ArrayDeque<>(); 63 | queue.add(this); 64 | final Iterator result = new Iterator() { 65 | @Override 66 | public boolean hasNext() { 67 | return !queue.isEmpty(); 68 | } 69 | @Override 70 | public ProofViewNode next() { 71 | final ProofViewNode node = queue.remove(); 72 | final List children = node.getChildren(); 73 | //Add children to front of queue for depth-first traversal: 74 | for (final Iterator it = new ArrayDeque(children) 75 | .descendingIterator() ; it.hasNext() ;) { 76 | queue.addFirst(it.next()); 77 | } 78 | return node; 79 | } 80 | }; 81 | return result; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/ProofViewGenerator.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: ProofViewGenerator.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.Cyc; 24 | import com.cyc.query.exception.ProofViewException; 25 | 26 | /** 27 | * Generates a {@link ProofView} for a specific answer to a query. 28 | * 29 | * @author nwinant 30 | */ 31 | public interface ProofViewGenerator extends QueryAnswerExplanationGenerator { 32 | 33 | //====| Factory methods |=================================================================// 34 | 35 | /** 36 | * Finds and returns a ProofViewGenerator instance. 37 | * 38 | * @param answer the answer for which to generate a ProofView. 39 | * @param spec the configuration parameters for ProofView generation. 40 | * 41 | * @return a ProofViewGenerator 42 | */ 43 | public static ProofViewGenerator get(QueryAnswer answer, ProofViewSpecification spec) { 44 | return Cyc.getProofViewService().getExplanationGenerator(answer, spec); 45 | } 46 | 47 | //====| Methods |=========================================================================// 48 | 49 | /** 50 | * Marshal this explanation into a DOM tree. 51 | * 52 | * @param destination 53 | */ 54 | void marshal(org.w3c.dom.Node destination); 55 | 56 | ProofViewMarshaller getMarshaller() throws ProofViewException; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/ProofViewMarshaller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Cycorp, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.cyc.query; 17 | 18 | /* 19 | * #%L 20 | * File: ProofViewMarshaller.java 21 | * Project: Core API 22 | * %% 23 | * Copyright (C) 2015 - 2019 Cycorp, Inc 24 | * %% 25 | * Licensed under the Apache License, Version 2.0 (the "License"); 26 | * you may not use this file except in compliance with the License. 27 | * You may obtain a copy of the License at 28 | * 29 | * http://www.apache.org/licenses/LICENSE-2.0 30 | * 31 | * Unless required by applicable law or agreed to in writing, software 32 | * distributed under the License is distributed on an "AS IS" BASIS, 33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 34 | * See the License for the specific language governing permissions and 35 | * limitations under the License. 36 | * #L% 37 | */ 38 | 39 | import com.cyc.query.exception.ProofViewException; 40 | import java.io.OutputStream; 41 | import java.io.Writer; 42 | 43 | /** 44 | * 45 | * @author nwinant 46 | */ 47 | public interface ProofViewMarshaller { 48 | 49 | //====| Methods |=========================================================================// 50 | 51 | /** 52 | * Output the specified ProofView to the specified DOM Node. 53 | * 54 | * @param destination 55 | * @throws com.cyc.query.exception.ProofViewException 56 | */ 57 | void marshal(org.w3c.dom.Node destination) throws ProofViewException; 58 | 59 | /** 60 | * Output the specified ProofView to the specified writer. 61 | * 62 | * @param destination 63 | * @throws com.cyc.query.exception.ProofViewException 64 | */ 65 | void marshal(Writer destination) throws ProofViewException; 66 | 67 | /** 68 | * Output the specified ProofView to the specified stream. 69 | * 70 | * @param destination 71 | * @throws com.cyc.query.exception.ProofViewException 72 | */ 73 | void marshal(OutputStream destination) throws ProofViewException; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/ProofViewNode.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: ProofViewNode.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.query.graph.GraphNodeAbsolutePath; 24 | import java.util.List; 25 | 26 | /** 27 | * 28 | * @author daves 29 | */ 30 | public interface ProofViewNode { 31 | 32 | public interface ProofViewNodePath extends GraphNodeAbsolutePath { 33 | } 34 | 35 | /** 36 | * The ID for this node. ProofViewNodes are unique within a ProofView. 37 | * 38 | * @return 39 | */ 40 | int getEntryId(); 41 | 42 | ProofViewNodePath getEntryPath(); 43 | 44 | List getChildren(); 45 | 46 | // Object getCycl(); 47 | String getCyclString(); 48 | 49 | int getDepth(); 50 | 51 | String getHTML(); 52 | 53 | /** 54 | * Get the label for this node. 55 | * 56 | * @return the label, or null if none. 57 | */ 58 | String getLabel(); 59 | 60 | /** 61 | * Get the parent node of this node. 62 | * 63 | * @return the parent node, or null if it has no parent. 64 | */ 65 | ProofViewNode getParent(); 66 | 67 | /** 68 | * Is it advised that this node be expanded when first displayed to expose its children? 69 | * 70 | * @return true iff it is so advised. 71 | */ 72 | boolean isExpandInitially(); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/ProofViewSpecification.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: ProofViewSpecification.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.Cyc; 24 | import com.cyc.kb.Context; 25 | 26 | /** 27 | * The configuration parameters which determine how a {@link ProofView} should be generated. 28 | * 29 | * @author daves 30 | */ 31 | public interface ProofViewSpecification extends QueryAnswerExplanationSpecification { 32 | 33 | //====| Factory methods |=================================================================// 34 | 35 | /** 36 | * Returns a new ProofViewSpecification object. 37 | * 38 | * @return a ProofViewSpecification. 39 | */ 40 | public static ProofViewSpecification get() { 41 | return Cyc.getProofViewService().getSpecification(); 42 | } 43 | 44 | //====| Methods |=========================================================================// 45 | 46 | public ProofViewSpecification setIncludeDetails(boolean includeDetails); 47 | 48 | public Boolean isIncludeDetails(); 49 | 50 | public ProofViewSpecification setIncludeLinear(boolean includeLinear); 51 | 52 | public Boolean isIncludeLinear(); 53 | 54 | public ProofViewSpecification setIncludeSummary(boolean includeSummary); 55 | 56 | public Boolean isIncludeSummary(); 57 | 58 | public ProofViewSpecification setDomainContext(Context domainContext); 59 | 60 | public Context getDomainContext(); 61 | 62 | public ProofViewSpecification setLanguageContext(Context languageContext); 63 | 64 | public Context getLanguageContext(); 65 | 66 | public ProofViewSpecification setIncludeAssertionBookkeeping(boolean includeBookkeeping); 67 | 68 | public Boolean isIncludeAssertionBookkeeping(); 69 | 70 | public ProofViewSpecification setIncludeAssertionCyclists(boolean includeAssertionCyclists); 71 | 72 | public Boolean isIncludeAssertionCyclists(); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/QueryAnswerExplanation.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: QueryAnswerExplanation.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.Cyc; 24 | 25 | /** 26 | * An explanation for a specific answer to a query. There is currently only one type of explanation 27 | * provided by the APIs -- {@link com.cyc.query.ProofView} -- but this interface exists to allow the 28 | * possibility of alternate types. 29 | * 30 | *

31 | * Note that in earlier API versions, this was sometimes referred to as a "Justification". To reduce 32 | * ambiguity, this interface has been renamed as of Core API 1.0.0. 33 | * 34 | * @author daves 35 | */ 36 | public interface QueryAnswerExplanation { 37 | 38 | //====| Factory methods |=================================================================// 39 | 40 | /** 41 | * Returns an explanation for an answer, generating one if necessary via a call to 42 | * {@link QueryAnswerExplanationGenerator#generate()}. 43 | * 44 | * @param type of QueryAnswerExplanation to be generated. 45 | * @param answer the answer for which to generate a QueryAnswerExplanation. 46 | * @param spec the configuration parameters for QueryAnswerExplanation generation. 47 | * 48 | * @return a QueryAnswerExplanation. 49 | */ 50 | public static 51 | T get(QueryAnswer answer, QueryAnswerExplanationSpecification spec) { 52 | return Cyc.findExplanationService(answer, spec).getExplanation(answer, spec); 53 | } 54 | 55 | //====| Methods |=========================================================================// 56 | 57 | } 58 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/QueryAnswerExplanationGenerator.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: QueryAnswerExplanationGenerator.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | 25 | import com.cyc.Cyc; 26 | import com.cyc.session.exception.OpenCycUnsupportedFeatureException; 27 | 28 | /** 29 | * An interface for representing and generating {@link QueryAnswerExplanation}s for a specific 30 | * answer to a query. 31 | * 32 | * @author baxter 33 | * @param type of QueryAnswerExplanation to be generated 34 | */ 35 | public interface QueryAnswerExplanationGenerator { 36 | 37 | //====| Factory methods |=================================================================// 38 | 39 | /** 40 | * Finds and returns an instance of a QueryAnswerExplanationGenerator suitable for 41 | * generating and returning a QueryAnswerExplanation for a given 42 | * QueryAnswerExplanationSpecification. 43 | * 44 | * @param type of QueryAnswerExplanation to be generated. 45 | * @param answer the answer for which to generate a QueryAnswerExplanation. 46 | * @param spec the configuration parameters for QueryAnswerExplanation generation. 47 | * 48 | * @return a QueryAnswerExplanationGenerator. 49 | */ 50 | public static 51 | QueryAnswerExplanationGenerator get(QueryAnswer answer, 52 | QueryAnswerExplanationSpecification spec) { 53 | return Cyc.findExplanationService(answer, spec).getExplanationGenerator(answer, spec); 54 | } 55 | 56 | //====| Methods |=========================================================================// 57 | 58 | /** 59 | * Return the explanation, generating one if necessary via a call to {@link #generate()}. 60 | * 61 | * @return a QueryAnswerExplanation 62 | * @throws OpenCycUnsupportedFeatureException when run against an OpenCyc server 63 | */ 64 | T getExplanation() throws OpenCycUnsupportedFeatureException; 65 | 66 | /** 67 | * Flesh out this explanation, setting its root node and tree structure underneath the root. 68 | * 69 | * @throws OpenCycUnsupportedFeatureException when run against an OpenCyc server 70 | */ 71 | void generate() throws OpenCycUnsupportedFeatureException; 72 | 73 | /** 74 | * Returns the inference answer justified by this object 75 | * 76 | * @return the inference answer 77 | */ 78 | QueryAnswer getAnswer(); 79 | 80 | } 81 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/QueryAnswerExplanationSpecification.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: QueryAnswerExplanationSpecification.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * The configuration parameters which determine how a QueryAnswerExplanation should be generated. 26 | * 27 | * @author daves 28 | * @param type of QueryAnswerExplanation 29 | */ 30 | public interface QueryAnswerExplanationSpecification { 31 | 32 | Class forExplanationType(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/QueryListener.java: -------------------------------------------------------------------------------- 1 | /* $Id: QueryListener.java 185299 2019-01-14 16:15:35Z daves $ 2 | */ 3 | 4 | package com.cyc.query; 5 | 6 | /* 7 | * #%L 8 | * File: QueryListener.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | 27 | import java.util.List; 28 | 29 | /** 30 | * This interface is one that must be implemented by anyone wishing to listen in 31 | * on events generated by a Query. 32 | * 33 | * @see Query 34 | * @author tbrussea, zelal 35 | * @version $Id: QueryListener.java 185299 2019-01-14 16:15:35Z daves $ 36 | */ 37 | public interface QueryListener { 38 | 39 | /** 40 | * This method is called when Cyc has created an inference for the query. That 41 | * means work has begun to find answers. 42 | * 43 | * @param query 44 | */ 45 | public void notifyInferenceCreated(Query query); 46 | 47 | /** 48 | * This method is called when the inference status has changed. 49 | * 50 | * @param oldStatus 51 | * @param newStatus 52 | * @param suspendReason 53 | * @param query 54 | */ 55 | public void notifyInferenceStatusChanged(InferenceStatus oldStatus, InferenceStatus newStatus, 56 | InferenceSuspendReason suspendReason, Query query); 57 | 58 | /** 59 | * Called when new answers have been found. 60 | * 61 | * @param query 62 | * @param newAnswers 63 | */ 64 | public void notifyInferenceAnswersAvailable(Query query, List newAnswers); 65 | 66 | /** 67 | * Called when the inference has been terminated. 68 | * 69 | * @param query 70 | * @param exception 71 | */ 72 | public void notifyInferenceTerminated(Query query, Exception exception); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/QueryRules.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query; 2 | 3 | /* 4 | * #%L 5 | * File: QueryRules.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.kb.Rule; 24 | import com.cyc.query.exception.QueryConstructionException; 25 | import com.cyc.session.exception.SessionCommunicationException; 26 | import java.util.Collection; 27 | 28 | /** 29 | * 30 | * @author nwinant 31 | */ 32 | public interface QueryRules { 33 | 34 | Collection getAllowedRules() throws SessionCommunicationException; 35 | 36 | Collection getForbiddenRules() throws SessionCommunicationException; 37 | 38 | Collection getPracticeRules() throws SessionCommunicationException; 39 | 40 | /** 41 | * Relevant only for queries loaded from the KB (instances of CycLQuerySpecification), this loads 42 | * all of the rules specified on the query and only allows Cyc to use those rules when running 43 | * this query. 44 | *

45 | * This is normally performed automatically by Cyc, but some older releases may not do so. 46 | * 47 | * @param includePracticeRules whether to include queryPracticeRules 48 | * 49 | * @throws QueryConstructionException 50 | * @throws SessionCommunicationException 51 | */ 52 | void useOnlySpecifiedRules(boolean includePracticeRules) 53 | throws QueryConstructionException, SessionCommunicationException; 54 | 55 | /** 56 | * If any rules are specified on the inference parameters for this query, remove them and let Cyc 57 | * decide what rules are relevant. 58 | */ 59 | void allowAllRules(); 60 | 61 | } 62 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/exception/ProofViewException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.exception; 2 | 3 | /* 4 | * #%L 5 | * File: ProofViewException.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import java.util.Objects; 24 | 25 | /** 26 | * The class of {@link Exception} thrown when a {@link com.cyc.query.ProofView} cannot be 27 | * provided as specified. 28 | * 29 | * @author baxter 30 | */ 31 | public class ProofViewException extends QueryException { 32 | 33 | //====| Factory methods |=================================================================// 34 | 35 | /** 36 | * Converts a Throwable to a ProofViewException. If the Throwable is a 37 | * ProofViewException, it will be passed through unmodified; otherwise, it will be wrapped 38 | * in a new ProofViewException. 39 | * 40 | * @param cause the Throwable to convert 41 | * 42 | * @return a ProofViewException 43 | */ 44 | public static ProofViewException fromThrowable(Throwable cause) { 45 | return (cause instanceof ProofViewException) 46 | ? (ProofViewException) cause 47 | : new ProofViewException(cause); 48 | } 49 | 50 | /** 51 | * Converts a Throwable to a ProofViewException with the specified detail message. If the 52 | * Throwable is a ProofViewException and if the Throwable's message is identical to the 53 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 54 | * a new ProofViewException with the detail message. 55 | * 56 | * @param cause the Throwable to convert 57 | * @param message the specified detail message 58 | * 59 | * @return a ProofViewException 60 | */ 61 | public static ProofViewException fromThrowable(String message, Throwable cause) { 62 | return (cause instanceof ProofViewException && Objects.equals(message, cause.getMessage())) 63 | ? (ProofViewException) cause 64 | : new ProofViewException(message, cause); 65 | } 66 | 67 | //====| Construction |====================================================================// 68 | 69 | protected ProofViewException(Throwable throwable) { 70 | super(throwable); 71 | } 72 | 73 | protected ProofViewException(String message, Throwable throwable) { 74 | super(message, throwable); 75 | } 76 | 77 | public ProofViewException(String message) { 78 | super(message); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/exception/QueryConstructionException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.exception; 2 | 3 | /* 4 | * #%L 5 | * File: QueryConstructionException.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import java.util.Objects; 24 | 25 | /** 26 | * The class of {@link Exception} thrown when a {@link com.cyc.query.Query} cannot be constructed as 27 | * specified. 28 | * 29 | * @author baxter 30 | */ 31 | public class QueryConstructionException extends QueryException { 32 | 33 | //====| Factory methods |=================================================================// 34 | 35 | /** 36 | * Converts a Throwable to a QueryConstructionException. If the Throwable is a 37 | * QueryConstructionException, it will be passed through unmodified; otherwise, it will be wrapped 38 | * in a new QueryConstructionException. 39 | * 40 | * @param cause the Throwable to convert 41 | * 42 | * @return a QueryConstructionException 43 | */ 44 | public static QueryConstructionException fromThrowable(Throwable cause) { 45 | return (cause instanceof QueryConstructionException) 46 | ? (QueryConstructionException) cause 47 | : new QueryConstructionException(cause); 48 | } 49 | 50 | /** 51 | * Converts a Throwable to a QueryConstructionException with the specified detail message. If the 52 | * Throwable is a QueryConstructionException and if the Throwable's message is identical to the 53 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 54 | * a new QueryConstructionException with the detail message. 55 | * 56 | * @param cause the Throwable to convert 57 | * @param message the specified detail message 58 | * 59 | * @return a QueryConstructionException 60 | */ 61 | public static QueryConstructionException fromThrowable(String message, Throwable cause) { 62 | return (cause instanceof QueryConstructionException && Objects.equals(message, cause.getMessage())) 63 | ? (QueryConstructionException) cause 64 | : new QueryConstructionException(message, cause); 65 | } 66 | 67 | //====| Construction |====================================================================// 68 | 69 | protected QueryConstructionException(Throwable throwable) { 70 | super(throwable); 71 | } 72 | 73 | protected QueryConstructionException(String message, Throwable throwable) { 74 | super(message, throwable); 75 | } 76 | 77 | public QueryConstructionException(String message) { 78 | super(message); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/exception/QueryException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.exception; 2 | 3 | /* 4 | * #%L 5 | * File: QueryException.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import java.util.Objects; 24 | 25 | /** 26 | * The root of the checked exception hierarchy in the Query API. 27 | * 28 | * @author baxter 29 | */ 30 | public class QueryException extends Exception { 31 | 32 | //====| Factory methods |=================================================================// 33 | 34 | /** 35 | * Converts a Throwable to a QueryException. If the Throwable is a QueryException, it will be 36 | * passed through unmodified; otherwise, it will be wrapped in a new QueryException. 37 | * 38 | * @param cause the Throwable to convert 39 | * 40 | * @return a QueryException 41 | */ 42 | public static QueryException fromThrowable(Throwable cause) { 43 | return (cause instanceof QueryException) 44 | ? (QueryException) cause 45 | : new QueryException(cause); 46 | } 47 | 48 | /** 49 | * Converts a Throwable to a QueryException with the specified detail message. If the Throwable is 50 | * a QueryException and if the Throwable's message is identical to the one supplied, the Throwable 51 | * will be passed through unmodified; otherwise, it will be wrapped in a new QueryException with 52 | * the detail message. 53 | * 54 | * @param cause the Throwable to convert 55 | * @param message the specified detail message 56 | * 57 | * @return a QueryException 58 | */ 59 | public static QueryException fromThrowable(String message, Throwable cause) { 60 | return (cause instanceof QueryException && Objects.equals(message, cause.getMessage())) 61 | ? (QueryException) cause 62 | : new QueryException(message, cause); 63 | } 64 | 65 | //====| Construction |====================================================================// 66 | 67 | public QueryException(final String message) { 68 | super(message); 69 | } 70 | 71 | protected QueryException(final String message, final Throwable cause) { 72 | super(message, cause); 73 | } 74 | 75 | protected QueryException(final Throwable cause) { 76 | super(cause); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/exception/QueryRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.exception; 2 | 3 | /* 4 | * #%L 5 | * File: QueryRuntimeException.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import java.util.Objects; 24 | 25 | /** 26 | * The root of the unchecked exception hierarchy in the Query API. 27 | * 28 | * @author baxter 29 | */ 30 | public class QueryRuntimeException extends RuntimeException { 31 | 32 | //====| Factory methods |=================================================================// 33 | 34 | /** 35 | * Converts a Throwable to a QueryRuntimeException. If the Throwable is a QueryRuntimeException, 36 | * it will be passed through unmodified; otherwise, it will be wrapped in a new 37 | * QueryRuntimeException. 38 | * 39 | * @param t the Throwable to convert 40 | * 41 | * @return a QueryRuntimeException 42 | */ 43 | public static QueryRuntimeException fromThrowable(Throwable t) { 44 | return (t instanceof QueryRuntimeException) 45 | ? (QueryRuntimeException) t 46 | : new QueryRuntimeException(t); 47 | } 48 | 49 | /** 50 | * Converts a Throwable to a QueryRuntimeException with the specified detail message. If the 51 | * Throwable is a QueryRuntimeException and if the Throwable's message is identical to the one 52 | * supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in a 53 | * new QueryRuntimeException with the detail message. 54 | * 55 | * @param t the Throwable to convert 56 | * @param message the specified detail message 57 | * 58 | * @return a QueryRuntimeException 59 | */ 60 | public static QueryRuntimeException fromThrowable(String message, Throwable t) { 61 | return (t instanceof QueryRuntimeException && Objects.equals(message, t.getMessage())) 62 | ? (QueryRuntimeException) t 63 | : new QueryRuntimeException(message, t); 64 | } 65 | 66 | //====| Construction |====================================================================// 67 | 68 | public QueryRuntimeException(final String message) { 69 | super(message); 70 | } 71 | 72 | protected QueryRuntimeException(final String message, final Throwable cause) { 73 | super(message, cause); 74 | } 75 | 76 | protected QueryRuntimeException(final Throwable cause) { 77 | super(cause); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Query API exception hierarchy. 3 | * 4 | * {@link com.cyc.query.exception.QueryException} and 5 | * {@link com.cyc.query.exception.QueryRuntimeException} are the root level 6 | * exceptions for Query API. All other exceptions thrown by the API are 7 | * sub-classes of these two classes. 8 | * 9 | * Refer to individual exception documentation for more details. 10 | */ 11 | package com.cyc.query.exception; 12 | 13 | /* 14 | * #%L 15 | * File: package-info.java 16 | * Project: Core API 17 | * %% 18 | * Copyright (C) 2015 - 2019 Cycorp, Inc 19 | * %% 20 | * Licensed under the Apache License, Version 2.0 (the "License"); 21 | * you may not use this file except in compliance with the License. 22 | * You may obtain a copy of the License at 23 | * 24 | * http://www.apache.org/licenses/LICENSE-2.0 25 | * 26 | * Unless required by applicable law or agreed to in writing, software 27 | * distributed under the License is distributed on an "AS IS" BASIS, 28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 29 | * See the License for the specific language governing permissions and 30 | * limitations under the License. 31 | * #L% 32 | */ 33 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/graph/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Query API graph utilities. 3 | */ 4 | package com.cyc.query.graph; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/metrics/InferenceMetric.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.metrics; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceMetric.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | /** 24 | * An interface representing an inference metric. Inference metrics are a way of telling Cyc's 25 | * inference engine to collect a certain type of data for later inspection. The most common metrics 26 | * are in {@link StandardInferenceMetric}. 27 | * 28 | * @author baxter 29 | */ 30 | public interface InferenceMetric { 31 | 32 | /** 33 | * Return the name by which this metric is known to Cyc. 34 | * 35 | * @return the name 36 | */ 37 | String getName(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/metrics/InferenceMetrics.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.metrics; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceMetrics.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.query.parameters.InferenceParameterValue; 24 | import java.util.Set; 25 | 26 | /** 27 | * A Set of {@link InferenceMetric} values. 28 | * 29 | * Inference metrics are a way of telling Cyc's inference engine to collect a certain type of data 30 | * for later inspection. The most common metrics are in {@link StandardInferenceMetric}. 31 | * 32 | * @author nwinant 33 | */ 34 | public interface InferenceMetrics extends Set, InferenceParameterValue { 35 | 36 | } 37 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/metrics/InferenceMetricsValues.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.metrics; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceMetricsValues.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | public interface InferenceMetricsValues { 24 | 25 | public abstract Object getValue(InferenceMetric metric); 26 | 27 | public abstract Object getValue(String metric); 28 | } 29 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/metrics/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Interfaces for inference metrics, which tell Cyc's inference engine to collect certain types of 3 | * data for later inspection. 4 | */ 5 | package com.cyc.query.metrics; 6 | 7 | /* 8 | * #%L 9 | * File: package-info.java 10 | * Project: Core API 11 | * %% 12 | * Copyright (C) 2015 - 2019 Cycorp, Inc 13 | * %% 14 | * Licensed under the Apache License, Version 2.0 (the "License"); 15 | * you may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at 17 | * 18 | * http://www.apache.org/licenses/LICENSE-2.0 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * #L% 26 | */ 27 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Interfaces for asking arbitrarily complex queries of a Cyc server, and processing the answers. 3 | */ 4 | package com.cyc.query; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/Browsable.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: Browsable.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * 26 | * @author baxter 27 | */ 28 | public enum Browsable implements InferenceParameterValue { 29 | 30 | /** 31 | * @deprecated. Equivalent to NEVER. 32 | */ 33 | NIL, /** 34 | /** 35 | * @deprecated. Equivalent to ALWAYS. 36 | */ 37 | T, /** 38 | /** 39 | * The inference will always be browsable. 40 | */ 41 | ALWAYS, /** 42 | * If the inference engine chooses to create a browsable object, it will be browsable. But it might choose to not create one, 43 | * and it will therefore not be browsable. Use of this value via the Query API is not advised, as it may leave inference objects 44 | * on the Cyc server that are not cleaned up with the close() method is called on the inference. @todo Ensure that 45 | * maybe-browsable inferences do get cleaned up when close() is called. 46 | */ 47 | MAYBE, /** 48 | * This inference will not be browsable. 49 | */ 50 | NEVER; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/DisjunctionFreeElVarsPolicy.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: DisjunctionFreeElVarsPolicy.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * 26 | * @author baxter 27 | */ 28 | public enum DisjunctionFreeElVarsPolicy implements InferenceParameterValue { 29 | 30 | /** 31 | * Compute the intersection of EL variables in disjuncts. * 32 | */ 33 | COMPUTE_INTERSECTION, 34 | /** 35 | * Compute the union of EL variables in disjuncts. * 36 | */ 37 | COMPUTE_UNION, 38 | /** 39 | * Each disjunct must have the exact same set of EL variables. 40 | */ 41 | REQUIRE_EQUAL; 42 | 43 | @Override 44 | public String toString() { 45 | return ":" + name().replace("_", "-"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/InferenceAnswerLanguage.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceAnswerLanguage.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * The CycL language used to express answers. 26 | * 27 | * @author baxter 28 | */ 29 | public enum InferenceAnswerLanguage implements InferenceParameterValue { 30 | 31 | /** 32 | * Epistemological Level. The way knowledge is expressed when Cyc communicates 33 | * with users or external programs. 34 | */ 35 | EL, 36 | /** 37 | * Heuristic Level. The way knowledge is actually stored, and inference 38 | * implemented, in Cyc. 39 | */ 40 | HL; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/InferenceMode.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceMode.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * 26 | * @author nwinant 27 | */ 28 | public interface InferenceMode { 29 | public InferenceParameterValueDescription getDescription(); 30 | } 31 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/InferenceParameter.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceParameter.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * @author tbrussea 26 | * @date August 2, 2005, 10:25 AM 27 | * @version $Id: InferenceParameter.java 185299 2019-01-14 16:15:35Z daves $ 28 | */ 29 | public interface InferenceParameter { 30 | 31 | /* @return the CycList API value for val qua value for this parameter. */ 32 | Object parameterValueCycListApiValue(Object val); 33 | 34 | /** 35 | * Canonicalize a value for this parameter. 36 | * @param value 37 | * @return the canonical form of the value. 38 | */ 39 | Object canonicalizeValue(Object value); 40 | 41 | /** 42 | * Get a short description of this parameter. 43 | * @return the description 44 | */ 45 | String getShortDescription(); 46 | 47 | /** 48 | * Get a long description of this parameter. 49 | * @return the description. 50 | */ 51 | String getLongDescription(); 52 | 53 | /** 54 | * Get a human-friendly string representation of the specified value. 55 | * @param value 56 | * @return a pretty representation of the value. 57 | */ 58 | String getPrettyRepresentation(Object value); 59 | 60 | InferenceParameterValueDescription getAlternateValue(); 61 | 62 | boolean isAlternateValue(Object value); 63 | 64 | /** 65 | * Determine whether the specified value is valid for this parameter. 66 | * @param potentialValue 67 | * @return true if it is a valid value. 68 | */ 69 | boolean isValidValue(Object potentialValue); 70 | 71 | /** 72 | * 73 | * @return true if this is a basic parameter. 74 | */ 75 | boolean isBasicParameter(); 76 | 77 | /** 78 | * 79 | * @return true if this is a query static parameter. 80 | */ 81 | boolean isQueryStaticParameter(); 82 | 83 | /** 84 | * Get the default value for this parameter. 85 | * @return the default value. 86 | */ 87 | Object getDefaultValue(); 88 | } 89 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/InferenceParameterSymbolValue.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceParameterSymbolValue.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * 26 | * @author daves 27 | */ 28 | public interface InferenceParameterSymbolValue { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/InferenceParameterValue.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceParameterValue.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * A representation of a value for an inference parameter. 26 | * @see com.cyc.query.parameters.InferenceParameter 27 | * @author baxter 28 | */ 29 | public interface InferenceParameterValue { 30 | 31 | // /** 32 | // * Get the string API representation for this value. 33 | // * @return the string API representation. 34 | // */ 35 | // String stringApiValue(); 36 | // 37 | // /** 38 | // * Get the CycList API representation for this value. 39 | // * @return the CycList API representation. 40 | // */ 41 | // Object cycListApiValue(); 42 | // 43 | // /** 44 | // * Get the {@link Symbol} version of this value, if applicable. 45 | // * @return the symbol. 46 | // */ 47 | // Symbol getSymbol(); 48 | } 49 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/InferenceParameterValueDescription.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: InferenceParameterValueDescription.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | //// Internal Imports 25 | 26 | /** 27 | *

InferenceParameterValueDescription is designed to... 28 | * 29 | * @author zelal 30 | * @date August 14, 2005, 12:47 PM 31 | * @version $Id: InferenceParameterValueDescription.java 185299 2019-01-14 16:15:35Z daves $ 32 | */ 33 | public interface InferenceParameterValueDescription { 34 | 35 | void setValue(Object value); 36 | 37 | Object getValue(); 38 | 39 | String getShortDescription(); 40 | 41 | String getLongDescription(); 42 | } 43 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/ProblemReusePolicy.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: ProblemReusePolicy.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * Which problems are considered for reuse by the Worker (aka Problem Store). 26 | * Problems deemed "equal" are reused, but since equality reasoning can be 27 | * non-trivial, under some policies not all problems are checked. 28 | * 29 | * @author baxter 30 | */ 31 | public enum ProblemReusePolicy implements InferenceParameterValue { 32 | 33 | /** 34 | * The worker tries to do equality reasoning on all problems. 35 | */ 36 | ALL, 37 | /** 38 | * The worker tries to do equality reasoning only on single-literal problems. 39 | */ 40 | SINGLE_LITERAL, 41 | /** 42 | * The worker doesn't try to do equality reasoning on any kind of problem. 43 | */ 44 | NONE; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/ProofValidationMode.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: ProofValidationMode.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | 25 | /** 26 | * How carefully to check proofs for semantic well-formedness. 27 | * 28 | * @author baxter 29 | */ 30 | public enum ProofValidationMode implements InferenceParameterValue { 31 | 32 | /** 33 | * Full (most expensive). The intermediate proofs that are used in inference 34 | * are checked for all kinds of semantic well-formedness. 35 | */ 36 | ALL, 37 | /** 38 | * Only arg-type. The intermediate proofs that are used in inference are 39 | * checked only for arg-type constraints. 40 | */ 41 | ARG_TYPE, 42 | /** 43 | * Only HL validations. The intermediate proofs that are used in inference are 44 | * checked only for HL validations. 45 | */ 46 | MINIMAL, 47 | /** 48 | * None (least expensive). No semantic well-formedness checks are performed on 49 | * the intermediate proofs that are used in inference. 50 | */ 51 | NONE; 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/ResultUniqueness.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: ResultUniqueness.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * 26 | * @author baxter 27 | */ 28 | public enum ResultUniqueness implements InferenceParameterValue { 29 | 30 | /** 31 | * Two answers are considered the same if they assign the same bindings to all 32 | * open variables. 33 | */ 34 | BINDINGS, /** 35 | * Results can have the same answers, as long as they have distinct proofs. 36 | */ 37 | PROOF; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/TransitiveClosureMode.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.parameters; 2 | 3 | /* 4 | * #%L 5 | * File: TransitiveClosureMode.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * The degree to which modules (such as transitiveViaArg) should generate 26 | * transitive closures. 27 | * 28 | * @author baxter 29 | */ 30 | public enum TransitiveClosureMode implements InferenceParameterValue { 31 | 32 | /** 33 | * Full closures (very expensive). Transitivity modules will provide the 34 | * minimal answers and full transitive closures on the minimal answers. 35 | */ 36 | ALL, /** 37 | * Focused closures (expensive). Transitivity modules will provide the minimal 38 | * answers and focused transitive closures on the minimal answers. 39 | */ 40 | FOCUSED, 41 | /** 42 | * No closures. Transitivity modules will only provide the minimal answers 43 | * (and no transitive closures on the minimal answers). 44 | * 45 | */ 46 | NONE; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/parameters/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Interfaces for inference parameters, which determine how Cyc performs an inference. 3 | */ 4 | package com.cyc.query.parameters; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/spi/ProofViewService.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.spi; 2 | 3 | /* 4 | * #%L 5 | * File: ProofViewService.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.query.ProofView; 24 | import com.cyc.query.ProofViewGenerator; 25 | import com.cyc.query.ProofViewMarshaller; 26 | import com.cyc.query.ProofViewSpecification; 27 | import com.cyc.query.QueryAnswer; 28 | import com.cyc.query.QueryAnswerExplanationSpecification; 29 | 30 | /** 31 | * Service provider interface for factories which produce ProofViewGenerators. 32 | * 33 | * @author nwinant 34 | */ 35 | public interface ProofViewService extends QueryAnswerExplanationService { 36 | 37 | /** 38 | * Returns a new ProofViewSpecification object. 39 | * 40 | * @return a ProofViewSpecification. 41 | */ 42 | ProofViewSpecification getSpecification(); 43 | 44 | /** 45 | * Finds and returns a ProofViewGenerator instance. 46 | * 47 | * @param answer the answer for which to generate a ProofView. 48 | * @param spec the configuration parameters for ProofView generation. 49 | * 50 | * @return a ProofViewGenerator. 51 | */ 52 | @Override 53 | ProofViewGenerator getExplanationGenerator(QueryAnswer answer, 54 | QueryAnswerExplanationSpecification spec); 55 | 56 | /** 57 | * Returns a ProofView for an answer, generating one if necessary via a call to 58 | * {@link ProofViewGenerator#generate()}. 59 | * 60 | * @param answer the answer for which to generate a ProofView. 61 | * @param spec the configuration parameters for ProofView generation. 62 | * 63 | * @return a ProofView. 64 | */ 65 | @Override 66 | ProofView getExplanation(QueryAnswer answer, QueryAnswerExplanationSpecification spec); 67 | 68 | } 69 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/spi/QueryAnswerExplanationService.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.spi; 2 | 3 | /* 4 | * #%L 5 | * File: QueryAnswerExplanationService.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.query.QueryAnswer; 24 | import com.cyc.query.QueryAnswerExplanation; 25 | import com.cyc.query.QueryAnswerExplanationGenerator; 26 | import com.cyc.query.QueryAnswerExplanationSpecification; 27 | 28 | /** 29 | * Service provider interface for factories which produce QueryAnswerExplanationGenerators. 30 | * 31 | * @author nwinant 32 | * @param type of QueryAnswerExplanation 33 | */ 34 | public interface QueryAnswerExplanationService { 35 | 36 | /** 37 | * The type of QueryAnswerExplanation for which this service produces potentially suitable 38 | * QueryAnswerExplanationGenerators. This method is primarily used during application startup to 39 | * check that basic types of QueryAnswerExplanation are generally supported. Before an actual 40 | * QueryAnswerExplanationGenerator is requested, a more specific check will be performed with 41 | * {@link #isSuitableForSpecification(com.cyc.query.QueryAnswer, com.cyc.query.QueryAnswerExplanationSpecification) }. 42 | * 43 | * @return 44 | */ 45 | Class forExplanationType(); 46 | 47 | /** 48 | * Whether this service can provide a QueryAnswerExplanationGenerator suitable for a 49 | * specific QueryAnswer with a specific QueryAnswerExplanationSpecification. 50 | * This method is called whenever the QueryFactory is considering whether to request a 51 | * QueryAnswerExplanationGenerator from the service instance. 52 | * 53 | * @param answer 54 | * @param spec 55 | * 56 | * @return 57 | */ 58 | boolean isSuitableForSpecification(QueryAnswer answer, QueryAnswerExplanationSpecification spec); 59 | 60 | /** 61 | * Finds and returns an instance of a QueryAnswerExplanationGenerator suitable for 62 | * generating and returning a QueryAnswerExplanation for a given 63 | * QueryAnswerExplanationSpecification. 64 | * 65 | * @param answer the answer for which to generate a QueryAnswerExplanation. 66 | * @param spec the configuration parameters for QueryAnswerExplanation generation. 67 | * 68 | * @return a QueryAnswerExplanationGenerator. 69 | */ 70 | QueryAnswerExplanationGenerator getExplanationGenerator( 71 | QueryAnswer answer, QueryAnswerExplanationSpecification spec); 72 | 73 | /** 74 | * Returns an explanation for an answer, generating one if necessary via a call to 75 | * {@link QueryAnswerExplanationGenerator#generate()}. 76 | * 77 | * @param answer the answer for which to generate a QueryAnswerExplanation. 78 | * @param spec the configuration parameters for QueryAnswerExplanation generation. 79 | * 80 | * @return a QueryAnswerExplanation. 81 | */ 82 | T getExplanation(QueryAnswer answer, QueryAnswerExplanationSpecification spec); 83 | 84 | } 85 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/spi/QueryApiService.java: -------------------------------------------------------------------------------- 1 | package com.cyc.query.spi; 2 | 3 | /* 4 | * #%L 5 | * File: QueryApiService.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.CoreServicesLoader; 24 | import com.cyc.CycApiEntryPoint; 25 | import com.cyc.query.QueryAnswer; 26 | import com.cyc.query.QueryAnswerExplanation; 27 | import com.cyc.query.QueryAnswerExplanationSpecification; 28 | import java.util.List; 29 | 30 | /** 31 | * The primary entrypoint for a Query API implementation. 32 | * 33 | * @author nwinant 34 | */ 35 | public interface QueryApiService extends CycApiEntryPoint { 36 | 37 | QueryService getQueryService(); 38 | 39 | ProofViewService getProofViewService(); 40 | 41 | List getQueryExplanationFactoryServices(CoreServicesLoader loader); 42 | 43 | QueryAnswerExplanationService findExplanationService( 44 | CoreServicesLoader loader, 45 | QueryAnswer answer, 46 | QueryAnswerExplanationSpecification spec); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/query/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All Query API service provider interfaces. 3 | */ 4 | package com.cyc.query.spi; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/CycServerReleaseType.java: -------------------------------------------------------------------------------- 1 | package com.cyc.session; 2 | 3 | /* 4 | * #%L 5 | * File: CycServerReleaseType.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | /** 24 | * Enum representing Cyc server types. E.g., OpenCyc, ResearchCyc, EnterpriseCyc, etc. 25 | * 26 | * @author nwinant 27 | */ 28 | public enum CycServerReleaseType { 29 | 30 | OPENCYC("OpenCyc", "OCyc"), 31 | RESEARCHCYC("ResearchCyc", "RCyc"), 32 | ENTERPRISECYC("EnterpriseCyc", "ECyc"), 33 | MAINT("Cyc-Maint", "Maint"), 34 | OTHER(null, null); 35 | 36 | private final String name; 37 | private final String abbreviation; 38 | 39 | private CycServerReleaseType(String name, String abbreviation) { 40 | this.name = name; 41 | this.abbreviation = abbreviation; 42 | } 43 | 44 | public String getName() { 45 | return this.name; 46 | } 47 | 48 | public String getAbbreviation() { 49 | return this.abbreviation; 50 | } 51 | 52 | /** 53 | * Returns the CycServerReleaseType constant matching the specified String. This method is more 54 | * liberal than {@link com.cyc.session.CycServerReleaseType#valueOf(java.lang.String) } in that it 55 | * will match on either name or abbreviation, and is case-insensitive. (Like 56 | * CycServerReleaseType#valueOf(java.lang.String), extraneous whitespace characters are not 57 | * permitted.) 58 | * 59 | * @param string 60 | * 61 | * @return string 62 | */ 63 | public static CycServerReleaseType fromString(String string) { 64 | for (final CycServerReleaseType type : values()) { 65 | if (!OTHER.equals(type)) { 66 | if (type.getName().equalsIgnoreCase(string) 67 | || type.getAbbreviation().equalsIgnoreCase(string)) { 68 | return type; 69 | } 70 | } 71 | } 72 | return OTHER; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/CycSessionConfigurationProperties.java: -------------------------------------------------------------------------------- 1 | package com.cyc.session; 2 | 3 | /* 4 | * #%L 5 | * File: CycSessionConfigurationProperties.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | 24 | /** 25 | * This defines the canonical set of names for all {@link CycSessionConfiguration} properties. 26 | * Although some implementations of the CycSessionConfiguration interface may not require these 27 | * keys, they should be used in any implementation backed by {@link java.util.Properties} or any 28 | * form of map with String-based keys. 29 | * 30 | * @author nwinant 31 | */ 32 | public interface CycSessionConfigurationProperties { 33 | 34 | /** 35 | * The name of a configuration file to be loaded. 36 | * 37 | * @see CycSessionConfiguration#getConfigurationFileName() 38 | */ 39 | public static final String CONFIGURATION_FILE_KEY = "cyc.session.configurationFile"; 40 | 41 | /** 42 | * A requested {@link SessionConfigurationLoader}, as either the loader class's canonical name or 43 | * convenience name (i.e., matching {@link SessionConfigurationLoader#getName()}). 44 | * 45 | * @see CycSessionConfiguration#getConfigurationLoaderName() 46 | */ 47 | public static final String CONFIGURATION_LOADER_KEY = "cyc.session.configurationLoader"; 48 | 49 | /** 50 | * The address of Cyc server to be connected to, as a serialized {@link CycAddress} object; e.g. 51 | * localhost:3600. 52 | * 53 | * @see CycSessionConfiguration#getCycAddress() 54 | */ 55 | public static final String SERVER_KEY = "cyc.session.server"; 56 | 57 | /** 58 | * Returns an array of all property names. 59 | */ 60 | public static final String[] ALL_KEYS = { 61 | CONFIGURATION_FILE_KEY, 62 | CONFIGURATION_LOADER_KEY, 63 | SERVER_KEY 64 | }; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/exception/SessionCommandException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.session.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: SessionCommandException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * SessionCommandException indicates that Session implementation code could communicate with a Cyc 28 | * server, but encountered a problem issuing a command or interpreting a result. 29 | * 30 | * @author nwinant 31 | */ 32 | public class SessionCommandException extends SessionRuntimeException { 33 | 34 | 35 | //====| Factory methods |=================================================================// 36 | 37 | /** 38 | * Converts a Throwable to a SessionCommandException. If the Throwable is a 39 | * SessionCommandException, it will be passed through unmodified; otherwise, it will be wrapped 40 | * in a new SessionCommandException. 41 | * 42 | * @param cause the Throwable to convert 43 | * 44 | * @return a SessionCommandException 45 | */ 46 | public static SessionCommandException fromThrowable(Throwable cause) { 47 | return (cause instanceof SessionCommandException) 48 | ? (SessionCommandException) cause 49 | : new SessionCommandException(cause); 50 | } 51 | 52 | /** 53 | * Converts a Throwable to a SessionCommandException with the specified detail message. If the 54 | * Throwable is a SessionCommandException and if the Throwable's message is identical to the 55 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 56 | * a new SessionCommandException with the detail message. 57 | * 58 | * @param cause the Throwable to convert 59 | * @param message the specified detail message 60 | * 61 | * @return a SessionCommandException 62 | */ 63 | public static SessionCommandException fromThrowable(String message, Throwable cause) { 64 | return (cause instanceof SessionCommandException && Objects.equals(message, cause.getMessage())) 65 | ? (SessionCommandException) cause 66 | : new SessionCommandException(message, cause); 67 | } 68 | 69 | //====| Construction |====================================================================// 70 | 71 | 72 | /** 73 | * Construct a SessionCommandException object with no specified message. 74 | */ 75 | public SessionCommandException() { 76 | super(); 77 | } 78 | 79 | /** 80 | * Construct a SessionCommandException object with a specified message. 81 | * @param msg a message describing the exception. 82 | */ 83 | public SessionCommandException(String msg) { 84 | super(msg); 85 | } 86 | 87 | /** 88 | * Construct a SessionCommandException object with a specified message 89 | * and throwable. 90 | * @param msg the message string 91 | * @param cause the throwable that caused this exception 92 | */ 93 | protected SessionCommandException(String msg, Throwable cause) { 94 | super(msg, cause); 95 | } 96 | 97 | /** 98 | * Construct a SessionCommandException object with a specified throwable. 99 | * @param cause the throwable that caused this exception 100 | */ 101 | protected SessionCommandException(Throwable cause) { 102 | super(cause); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/exception/SessionException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.session.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: SessionException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | /** 26 | * SessionException is the base exception which indicates that an application library has 27 | * encountered a problem in interacting with a Cyc server. Subclasses of CycSessionException 28 | * indicate specific types of issues which the calling application might reasonably be expected to 29 | * prevent or respond to, such as misconfigured sessions. 30 | * 31 | * @see com.cyc.session.exception.SessionRuntimeException 32 | * 33 | * @author nwinant 34 | */ 35 | public class SessionException extends Exception { 36 | 37 | //====| Factory methods |=================================================================// 38 | 39 | /** 40 | * Converts a Throwable to a SessionException. If the Throwable is a 41 | * SessionException, it will be passed through unmodified; otherwise, it will be wrapped 42 | * in a new SessionException. 43 | * 44 | * @param cause the Throwable to convert 45 | * 46 | * @return a SessionException 47 | */ 48 | public static SessionException fromThrowable(Throwable cause) { 49 | return (cause instanceof SessionException) 50 | ? (SessionException) cause 51 | : new SessionException(cause); 52 | } 53 | 54 | /** 55 | * Converts a Throwable to a SessionException with the specified detail message. If the 56 | * Throwable is a SessionException and if the Throwable's message is identical to the 57 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 58 | * a new SessionException with the detail message. 59 | * 60 | * @param cause the Throwable to convert 61 | * @param message the specified detail message 62 | * 63 | * @return a SessionException 64 | */ 65 | public static SessionException fromThrowable(String message, Throwable cause) { 66 | return (cause instanceof SessionException && Objects.equals(message, cause.getMessage())) 67 | ? (SessionException) cause 68 | : new SessionException(message, cause); 69 | } 70 | 71 | //====| Construction |====================================================================// 72 | 73 | /** 74 | * Constructs a new exception with no specified message. 75 | */ 76 | public SessionException() { 77 | super(); 78 | } 79 | 80 | /** 81 | * Constructs a new exception with a specified message. 82 | * @param message a message describing the exception. 83 | */ 84 | public SessionException(String message) { 85 | super(message); 86 | } 87 | 88 | /** 89 | * Constructs a new exception with a specified message and throwable. 90 | * @param message the message string 91 | * @param cause the Throwable that caused this exception 92 | */ 93 | protected SessionException(String message, Throwable cause) { 94 | super(message, cause); 95 | } 96 | 97 | /** 98 | * Constructs a new exception with a specified throwable. 99 | * @param cause the throwable that caused this exception 100 | */ 101 | protected SessionException(Throwable cause) { 102 | super(cause); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/exception/SessionManagerException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.session.exception; 2 | 3 | import com.cyc.session.SessionManager; 4 | import java.util.Objects; 5 | 6 | /* 7 | * #%L 8 | * File: SessionManagerException.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | 27 | /** 28 | * Indicates an error with an existing {@link SessionManager}. 29 | * 30 | * @author nwinant 31 | */ 32 | public class SessionManagerException extends SessionException { 33 | 34 | //====| Factory methods |=================================================================// 35 | 36 | /** 37 | * Converts a Throwable to a SessionManagerException. If the Throwable is a 38 | * SessionManagerException, it will be passed through unmodified; otherwise, it will be wrapped 39 | * in a new SessionManagerException. 40 | * 41 | * @param cause the Throwable to convert 42 | * 43 | * @return a SessionManagerException 44 | */ 45 | public static SessionManagerException fromThrowable(Throwable cause) { 46 | return (cause instanceof SessionManagerException) 47 | ? (SessionManagerException) cause 48 | : new SessionManagerException(cause); 49 | } 50 | 51 | /** 52 | * Converts a Throwable to a SessionManagerException with the specified detail message. If the 53 | * Throwable is a SessionManagerException and if the Throwable's message is identical to the 54 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 55 | * a new SessionManagerException with the detail message. 56 | * 57 | * @param cause the Throwable to convert 58 | * @param message the specified detail message 59 | * 60 | * @return a SessionManagerException 61 | */ 62 | public static SessionManagerException fromThrowable(String message, Throwable cause) { 63 | return (cause instanceof SessionManagerException && Objects.equals(message, cause.getMessage())) 64 | ? (SessionManagerException) cause 65 | : new SessionManagerException(message, cause); 66 | } 67 | 68 | //====| Construction |====================================================================// 69 | 70 | 71 | /** 72 | * Construct a SessionManagerException object with no specified message. 73 | */ 74 | public SessionManagerException() { 75 | super(); 76 | } 77 | 78 | /** 79 | * Construct a SessionManagerException object with a specified message. 80 | * 81 | * @param msg a message describing the exception. 82 | */ 83 | public SessionManagerException(String msg) { 84 | super(msg); 85 | } 86 | 87 | /** 88 | * Construct a SessionManagerException object with a specified message and throwable. 89 | * 90 | * @param msg the message string 91 | * @param cause the throwable that caused this exception 92 | */ 93 | protected SessionManagerException(String msg, Throwable cause) { 94 | super(msg, cause); 95 | } 96 | 97 | /** 98 | * Construct a SessionManagerException object with a specified throwable. 99 | * 100 | * @param cause the throwable that caused this exception 101 | */ 102 | protected SessionManagerException(Throwable cause) { 103 | super(cause); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/exception/UnsupportedCycOperationException.java: -------------------------------------------------------------------------------- 1 | package com.cyc.session.exception; 2 | 3 | import java.util.Objects; 4 | 5 | /* 6 | * #%L 7 | * File: UnsupportedCycOperationException.java 8 | * Project: Core API 9 | * %% 10 | * Copyright (C) 2015 - 2019 Cycorp, Inc 11 | * %% 12 | * Licensed under the Apache License, Version 2.0 (the "License"); 13 | * you may not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * http://www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an "AS IS" BASIS, 20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | * #L% 24 | */ 25 | 26 | /** 27 | * Thrown to indicate that a Cyc server does not support a particular operation. 28 | * 29 | * @author nwinant 30 | */ 31 | public class UnsupportedCycOperationException extends SessionRuntimeException { 32 | 33 | //====| Factory methods |=================================================================// 34 | 35 | /** 36 | * Converts a Throwable to a UnsupportedCycOperationException. If the Throwable is a 37 | * UnsupportedCycOperationException, it will be passed through unmodified; otherwise, it will be wrapped 38 | * in a new UnsupportedCycOperationException. 39 | * 40 | * @param cause the Throwable to convert 41 | * 42 | * @return a UnsupportedCycOperationException 43 | */ 44 | public static UnsupportedCycOperationException fromThrowable(Throwable cause) { 45 | return (cause instanceof UnsupportedCycOperationException) 46 | ? (UnsupportedCycOperationException) cause 47 | : new UnsupportedCycOperationException(cause); 48 | } 49 | 50 | /** 51 | * Converts a Throwable to a UnsupportedCycOperationException with the specified detail message. If the 52 | * Throwable is a UnsupportedCycOperationException and if the Throwable's message is identical to the 53 | * one supplied, the Throwable will be passed through unmodified; otherwise, it will be wrapped in 54 | * a new UnsupportedCycOperationException with the detail message. 55 | * 56 | * @param cause the Throwable to convert 57 | * @param message the specified detail message 58 | * 59 | * @return a UnsupportedCycOperationException 60 | */ 61 | public static UnsupportedCycOperationException fromThrowable(String message, Throwable cause) { 62 | return (cause instanceof UnsupportedCycOperationException && Objects.equals(message, cause.getMessage())) 63 | ? (UnsupportedCycOperationException) cause 64 | : new UnsupportedCycOperationException(message, cause); 65 | } 66 | 67 | //====| Construction |====================================================================// 68 | 69 | /** 70 | * Constructs a new exception with no specified message. 71 | */ 72 | public UnsupportedCycOperationException() { 73 | super(); 74 | } 75 | 76 | /** 77 | * Constructs a new exception with a specified message. 78 | * @param message a message describing the exception. 79 | */ 80 | public UnsupportedCycOperationException(String message) { 81 | super(message); 82 | } 83 | 84 | /** 85 | * Constructs a new exception with a specified message and throwable. 86 | * @param message the message string 87 | * @param cause the throwable that caused this exception 88 | */ 89 | protected UnsupportedCycOperationException(String message, Throwable cause) { 90 | super(message, cause); 91 | } 92 | 93 | /** 94 | * Constructs a new exception with a specified throwable. 95 | * @param cause the throwable that caused this exception 96 | */ 97 | protected UnsupportedCycOperationException(Throwable cause) { 98 | super(cause); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Session API exception hierarchy. 3 | */ 4 | package com.cyc.session.exception; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Interfaces for configuring and managing connections to a Cyc server. 3 | *

4 | * The Session API defines simple, yet flexible configuration-driven management of Cyc sessions -- 5 | * such as acquiring server addresses, managing connections, etc. -- so that library and application 6 | * developers don't need to write it into their own code. At the same time, the API is extensible 7 | * enough developers can reasonably write their own modules to address unique configuration needs. 8 | *

9 | * End users should only need to directly interact with the classes and interfaces defined in 10 | * com.cyc.session. Interfaces and classes in sub-packages are for implementation providers. 11 | */ 12 | package com.cyc.session; 13 | 14 | /* 15 | * #%L 16 | * File: package-info.java 17 | * Project: Core API 18 | * %% 19 | * Copyright (C) 2015 - 2019 Cycorp, Inc 20 | * %% 21 | * Licensed under the Apache License, Version 2.0 (the "License"); 22 | * you may not use this file except in compliance with the License. 23 | * You may obtain a copy of the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, 29 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 30 | * See the License for the specific language governing permissions and 31 | * limitations under the License. 32 | * #L% 33 | */ 34 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/spi/SessionApiService.java: -------------------------------------------------------------------------------- 1 | package com.cyc.session.spi; 2 | 3 | /* 4 | * #%L 5 | * File: SessionApiService.java 6 | * Project: Core API 7 | * %% 8 | * Copyright (C) 2015 - 2019 Cycorp, Inc 9 | * %% 10 | * Licensed under the Apache License, Version 2.0 (the "License"); 11 | * you may not use this file except in compliance with the License. 12 | * You may obtain a copy of the License at 13 | * 14 | * http://www.apache.org/licenses/LICENSE-2.0 15 | * 16 | * Unless required by applicable law or agreed to in writing, software 17 | * distributed under the License is distributed on an "AS IS" BASIS, 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | * See the License for the specific language governing permissions and 20 | * limitations under the License. 21 | * #L% 22 | */ 23 | import com.cyc.CycApiEntryPoint; 24 | import com.cyc.session.SessionManager; 25 | import com.cyc.session.SessionManagerConfiguration; 26 | import com.cyc.session.exception.SessionManagerConfigurationException; 27 | import com.cyc.session.exception.SessionManagerException; 28 | import com.cyc.session.exception.SessionServiceException; 29 | 30 | /** 31 | * The primary entrypoint for a Session API implementation. 32 | * 33 | * @author nwinant 34 | */ 35 | public interface SessionApiService extends CycApiEntryPoint { 36 | 37 | /** 38 | * Returns the current SessionManager instance. 39 | * 40 | * @return 41 | */ 42 | SessionManager getSessionManager(); 43 | 44 | /** 45 | * Loads a new SessionManager, configured via the supplied SessionManagerConfiguration. The 46 | * previous SessionManager will be closed if it has not been closed already. 47 | * 48 | * @param configuration 49 | * 50 | * @return the new SessionManager 51 | * 52 | * @throws SessionServiceException 53 | * @throws SessionManagerException 54 | * @throws SessionManagerConfigurationException 55 | * 56 | * @see #reloadSessionManager() 57 | */ 58 | SessionManager reloadSessionManager(SessionManagerConfiguration configuration) 59 | throws SessionServiceException, SessionManagerException, SessionManagerConfigurationException; 60 | 61 | /** 62 | * Loads a new SessionManager with the default SessionManagerConfiguration. The previous 63 | * SessionManager will be closed if it has not been closed already. 64 | * 65 | * @return the new SessionManager 66 | * 67 | * @throws SessionServiceException 68 | * @throws SessionManagerException 69 | * 70 | * @see #reloadSessionManager(com.cyc.session.manager.SessionManagerConfiguration) 71 | */ 72 | SessionManager reloadSessionManager() 73 | throws SessionServiceException, SessionManagerException, SessionManagerConfigurationException; 74 | 75 | /* * 76 | * Returns the configuration for the SessionManager. 77 | * 78 | * @return 79 | * / 80 | SessionManagerConfiguration getConfiguration(); 81 | */ 82 | } 83 | -------------------------------------------------------------------------------- /core-api/src/main/java/com/cyc/session/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * All Session API service provider interfaces. 3 | */ 4 | package com.cyc.session.spi; 5 | 6 | /* 7 | * #%L 8 | * File: package-info.java 9 | * Project: Core API 10 | * %% 11 | * Copyright (C) 2015 - 2019 Cycorp, Inc 12 | * %% 13 | * Licensed under the Apache License, Version 2.0 (the "License"); 14 | * you may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * #L% 25 | */ 26 | -------------------------------------------------------------------------------- /core-api/src/main/resources/com/cyc/core/BuildInfo.properties: -------------------------------------------------------------------------------- 1 | ### 2 | # #%L 3 | # CoreAPISuite 4 | # %% 5 | # Copyright (C) 1995 - 2014 Cycorp, Inc 6 | # %% 7 | # This software is the proprietary information of Cycorp, Inc. 8 | # Use is subject to license terms. 9 | # #L% 10 | ### 11 | groupId = ${project.groupId} 12 | artifactId = ${project.artifactId} 13 | name = ${project.name} 14 | version = ${project.version} 15 | timeStamp = ${timestamp} 16 | scmRevision = ${cyc-core-api.revision} 17 | -------------------------------------------------------------------------------- /core-api/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | com.cyc.maven 10 | cyc-site-skin 11 | ${cyc-site-skin.version} 12 | 13 | 14 | 15 | 16 | 17 | 24 |

25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/site/resources/images/api-stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cycorp/api-suite/1d52affabc4635e3715a059e38741712cbdbf2d5/src/site/resources/images/api-stack.png --------------------------------------------------------------------------------