Skip to content

Commit

Permalink
Sketch new semantic builder
Browse files Browse the repository at this point in the history
  • Loading branch information
fvilla committed Jan 2, 2025
1 parent cc40590 commit 9f45ac2
Show file tree
Hide file tree
Showing 33 changed files with 3,505 additions and 3,669 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.integratedmodelling.cli.views;

import org.integratedmodelling.cli.KlabCLI;
import org.integratedmodelling.common.services.client.reasoner.ReasonerClient;
import org.integratedmodelling.common.utils.Utils;
import org.integratedmodelling.klab.api.configuration.Configuration;
import org.integratedmodelling.klab.api.data.Version;
Expand Down Expand Up @@ -125,14 +126,14 @@ public static class Strategy implements Runnable {

@Parameters java.util.List<String> observables;

@Option(
names = {"-a", "--acknowledgement"},
defaultValue = "false",
description = {
"Force a direct" + " observable to represent the acknowledgement of the observable."
},
required = false)
boolean acknowledge;
// @Option(
// names = {"-a", "--acknowledgement"},
// defaultValue = "false",
// description = {
// "Force a direct" + " observable to represent the acknowledgement of the observable."
// },
// required = false)
// boolean acknowledge;

@Override
public void run() {
Expand Down Expand Up @@ -163,15 +164,15 @@ public void run() {
return;
}

if (acknowledge) {
if (!observable.getDescriptionType().isInstantiation()) {
err.println(
CommandLine.Help.Ansi.AUTO.string(
"Cannot acknowledge something that is not" + " countable"));
return;
}
observable = observable.builder(ctx).as(DescriptionType.ACKNOWLEDGEMENT).build();
}
// if (acknowledge) {
// if (!observable.getDescriptionType().isInstantiation()) {
// err.println(
// CommandLine.Help.Ansi.AUTO.string(
// "Cannot acknowledge something that is not" + " countable"));
// return;
// }
// observable = observable.builder(ctx).as(DescriptionType.ACKNOWLEDGEMENT).build();
// }

var observation =
DigitalTwin.createObservation(
Expand Down Expand Up @@ -622,6 +623,13 @@ public static class Info implements Runnable {

@Spec CommandSpec commandSpec;

@Option(
names = {"-a", "--alternative"},
defaultValue = "false",
description = {"Include inherited " + "traits"},
required = false)
boolean alternative = false;

@Parameters java.util.List<String> arguments;

@Override
Expand Down Expand Up @@ -650,7 +658,14 @@ public void run() {

for (var urn : tokens.stream().map(l -> Utils.Strings.join(l, " ")).toList()) {

var concept = reasoner.resolveConcept(urn);
Concept concept = null;

if (alternative && reasoner instanceof ReasonerClient reasonerClient) {
concept = reasonerClient.resolveConceptAlternative(urn);
} else {
concept = reasoner.resolveConcept(urn);
}

if (concept != null) {
out.println(AUTO.string("Normalized URN: @|blue " + concept.getUrn() + "|@"));
out.println(describe(concept, reasoner));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,43 @@

public interface Concept extends Semantics {

/**
* @return
*/
Set<SemanticType> getType();

/**
* The 'collective' character ('each' ...) belongs to the observable and not to the concept, but for
* consistent parsing we must add it to the Concept and propagate it to the observable. When the Concept
* is used alone, the collective character should be ignored as it is an attribute of the observation
* (determining the {@link DescriptionType#INSTANTIATION}) and does not affect the semantics.
*
* @return
*/
boolean isCollective();

/**
* This returns null in "normal" concepts, while a concept qualified with <code>any</code>,
* <code>all</code> or
* <code>no</code> will return, respectively, {@link LogicalConnector#UNION},
* {@link LogicalConnector#INTERSECTION} or , {@link LogicalConnector#EXCLUSION}.
*
* @return
*/
LogicalConnector getQualifier();
/**
* @return
*/
Set<SemanticType> getType();

/**
* The 'collective' character ('each' ...) belongs to the observable and not to the concept, but
* for consistent parsing we must add it to the Concept and propagate it to the observable. When
* the Concept is used alone, the collective character should be ignored as it is an attribute of
* the observation (determining the {@link DescriptionType#INSTANTIATION}) and does not affect the
* semantics.
*
* @return
*/
boolean isCollective();

/**
* This returns null in "normal" concepts, while a concept qualified with <code>any</code>, <code>
* all</code> or <code>no</code> will return, respectively, {@link LogicalConnector#UNION}, {@link
* LogicalConnector#INTERSECTION} or , {@link LogicalConnector#EXCLUSION}.
*
* @return
*/
LogicalConnector getQualifier();

/**
* Make and return the singular version of this concept.
*
* @return
*/
Concept singular();

/**
* Make and return the collective version of this concept. Calling this on anything other than a
* substantial will throw an exception.
*
* @return
*/
Concept collective();
}
Loading

0 comments on commit 9f45ac2

Please sign in to comment.