Skip to content

Commit

Permalink
Many KimConcept parsing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fvilla committed Jan 3, 2025
1 parent 9f45ac2 commit 3efcb28
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,184 +11,199 @@
import java.util.Set;

/**
* A KimConcept is the declaration of a concept, i.e. a semantic expression built out of known concepts and
* conforming to k.IM semantic constraints. Concept expressions compile to this structure, which retains the
* final concept names only as fully qualified names. External infrastructure can create the actual concepts
* that a reasoner can operate on.
* A KimConcept is the declaration of a concept, i.e. a semantic expression built out of known
* concepts and conforming to k.IM semantic constraints. Concept expressions compile to this
* structure, which retains the final concept names only as fully qualified names. External
* infrastructure can create the actual concepts that a reasoner can operate on.
*
* @author ferdinando.villa
*/
public interface KimConcept extends KlabStatement {

enum Expression {
SINGLETON, UNION, INTERSECTION
enum Expression {
SINGLETON,
UNION,
INTERSECTION
}

/**
* A simple data structure containing the essential info about a basic concept that can be output
* by any resource service that distributes or serves the worldview.
*
* @param namespace
* @param conceptName
* @param mainDeclaredType
* @param label
* @param description
* @param isAbstract
*/
public record Descriptor(
String namespace,
String conceptName,
SemanticType mainDeclaredType,
String label,
String description,
boolean isAbstract) {
@Override
public String toString() {
return (isAbstract ? "abstract " : "")
+ mainDeclaredType.name().toLowerCase()
+ " "
+ namespace
+ ":"
+ conceptName;
}

/**
* A simple data structure containing the essential info about a basic concept that can be output by any
* resource service that distributes or serves the worldview.
*
* @param namespace
* @param conceptName
* @param mainDeclaredType
* @param label
* @param description
* @param isAbstract
*/
public record Descriptor(String namespace, String conceptName, SemanticType mainDeclaredType,
String label,
String description, boolean isAbstract) {
@Override
public String toString() {
return (isAbstract ? "abstract " : "") + mainDeclaredType.name().toLowerCase() + " " + namespace + ":" + conceptName;
}
}

/**
* A leaf declaration contains a name (e.g. 'elevation:Geography'); all others do not. When the name is
* not null, there still may be a negation or a semantic operator.
*
* @return the concept name or null.
*/
String getName();

/**
* The type contains all declared attributes for the concept. An empty type denotes an inconsistent
* concept. The k.IM validator ensures that any non-empty types are internally consistent.
*
* @return the set of types
*/
Set<SemanticType> getType();

/**
* The main observable, which must be unique. This is null in a leaf declaration, where {@link #getName()}
* returns a non-null value.
*
* @return the main observable
*/
KimConcept getObservable();

KimConcept getInherent();

KimConcept getGoal();

KimConcept getCausant();

KimConcept getCaused();

KimConcept getCompresent();

KimConcept getComparisonConcept();

String getAuthorityTerm();

String getAuthority();

UnarySemanticOperator getSemanticModifier();

KimConcept getRelationshipSource();

KimConcept getRelationshipTarget();

List<KimConcept> getTraits();

List<KimConcept> getRoles();

boolean isNegated();

boolean is(SemanticType type);

/**
* Collective resolution/perspective linked to the <code>each</code> keyword in the expression. This
* determines the perspective in resolution: if a countable, resolution is instantiation; if an inherency
* for a quality or predicate, the resolution happens "all at once".
*
* @return
*/
boolean isCollective();

/**
* @param visitor
*/
/**
* If {@link #getExpressionType()} returns anything other than {@link Expression#SINGLETON}, the operands
* are other declarations this is part of a union or intersection with.
*
* @return the operands
*/
List<KimConcept> getOperands();

/**
* Type of expression. If anything other than {@link Expression#SINGLETON}, {@link #getOperands()} will
* return a non-empty list.
*
* @return the expression type
*/
Expression getExpressionType();

/**
* Get the fundamental type of this concept - one of the concrete trait or observable types, including
* configuration and extent.
*
* @return
*/
SemanticType getFundamentalType();

/**
* Get the 'co-occurrent' (during) event type if any.
*
* @return
*/
KimConcept getCooccurrent();

/**
* Get the concept that this is stated to be adjacent to if any.
*
* @return
*/
KimConcept getAdjacent();

/**
* Return a string suitable for naming a k.IM object after this concept.
*
* @return
*/
String getCodeName();

SemanticRole getSemanticRole();

/**
* Declared parent concept, if any.
*
* @return
*/
KimConcept getParent();

boolean isPattern();

Collection<String> getPatternVariables();

/**
* If the concept is the result of a unary operation applied to one or two arguments, return the operator along with its
* argument. Otherwise return null;
*
* @return
*/
Triple<UnarySemanticOperator, KimConcept, KimConcept> semanticOperation();

/**
* If the concept contains the passed modifier, return its argument, otherwise return null.
*
* @param semanticClause
* @return
*/
KimConcept semanticClause(SemanticClause semanticClause);

// /**
// * Return any temporal inherency for this occurrent ('during each').
// *
// * @return
// */
// KimConcept getTemporalInherent();

}

/**
* A leaf declaration contains a name (e.g. 'elevation:Geography'); all others do not. When the
* name is not null, there still may be a negation or a semantic operator.
*
* @return the concept name or null.
*/
String getName();

/**
* The main observable, which must be unique. This is null in a leaf declaration, where {@link
* #getName()} returns a non-null value.
*
* @return the main observable
*/
KimConcept getObservable();

/**
* The type contains all declared attributes for the concept. An empty type denotes an
* inconsistent concept. The k.IM validator ensures that any non-empty types are internally
* consistent.
*
* @return the set of types
*/
Set<SemanticType> getType();

KimConcept getInherent();

KimConcept getGoal();

KimConcept getCausant();

KimConcept getCaused();

KimConcept getCompresent();

KimConcept getComparisonConcept();

String getAuthorityTerm();

String getAuthority();

UnarySemanticOperator getSemanticModifier();

KimConcept getRelationshipSource();

KimConcept getRelationshipTarget();

List<KimConcept> getTraits();

List<KimConcept> getRoles();

boolean isNegated();

boolean is(SemanticType type);

/**
* Add or set the unary operator, returning a new concept
*
* @param operator
* @param operand
* @param comparisonConcept
* @return
*/
KimConcept addOperator(
UnarySemanticOperator operator, KimConcept operand, KimConcept comparisonConcept);

/**
* Collective resolution/perspective linked to the <code>each</code> keyword in the expression.
* This determines the perspective in resolution: if a countable, resolution is instantiation; if
* an inherency for a quality or predicate, the resolution happens "all at once".
*
* @return
*/
boolean isCollective();

/**
* @param visitor
*/
/**
* If {@link #getExpressionType()} returns anything other than {@link Expression#SINGLETON}, the
* operands are other declarations this is part of a union or intersection with.
*
* @return the operands
*/
List<KimConcept> getOperands();

/**
* Type of expression. If anything other than {@link Expression#SINGLETON}, {@link #getOperands()}
* will return a non-empty list.
*
* @return the expression type
*/
Expression getExpressionType();

/**
* Get the fundamental type of this concept - one of the concrete trait or observable types,
* including configuration and extent.
*
* @return
*/
SemanticType getFundamentalType();

/**
* Get the 'co-occurrent' (during) event type if any.
*
* @return
*/
KimConcept getCooccurrent();

/**
* Get the concept that this is stated to be adjacent to if any.
*
* @return
*/
KimConcept getAdjacent();

/**
* Return a string suitable for naming a k.IM object after this concept.
*
* @return
*/
String getCodeName();

// SemanticRole getSemanticRole();

/**
* Declared parent concept, if any.
*
* @return
*/
KimConcept getParent();

boolean isPattern();

Collection<String> getPatternVariables();

/**
* If the concept is the result of a unary operation applied to one or two arguments, return the
* operator along with its argument. Otherwise return null;
*
* @return
*/
Triple<UnarySemanticOperator, KimConcept, KimConcept> semanticOperation();

/**
* If the concept contains the passed modifier, return its argument, otherwise return null.
*
* @param semanticClause
* @return
*/
KimConcept semanticClause(SemanticClause semanticClause);
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public KlabAsset.KnowledgeClass getType() {
public void setType(KlabAsset.KnowledgeClass type) {
this.type = type;
}

@Override
public String toString() {
return offsetInDocument + "/" + length;
}
}

public NotificationImpl() {
Expand Down
Loading

0 comments on commit 3efcb28

Please sign in to comment.