📄 compactparser.jj
字号:
return null;
}
}
}
OWLMinCardinality OWLMinCardinality(RDFProperty slot) :
{
int card;
}
{
">" card=CardinalityValue()
{
checkFeatureSupported(OWLProfiles.MinCardinality_Restrictions);
if(create) {
return owlModel.createOWLMinCardinality(slot, card);
}
else {
return null;
}
}
}
OWLCardinality OWLCardinality(RDFProperty slot) :
{
int card;
}
{
"=" card=CardinalityValue()
{
checkFeatureSupported(OWLProfiles.MinCardinality_Restrictions);
checkFeatureSupported(OWLProfiles.MaxCardinality_Restrictions);
if(create) {
return owlModel.createOWLCardinality(slot, card);
}
else {
return null;
}
}
}
OWLHasValue OWLHasValue(RDFProperty slot) :
{
Object value;
}
{
"$" value=OWLHasValueValue()
{
checkFeatureSupported(OWLProfiles.HasValue_Restrictions);
if(!(slot instanceof OWLDatatypeProperty)) {
if(OWLUtil.hasOWLDLProfile(owlModel) && (value instanceof Cls || value instanceof Slot)) {
value = null;
}
if(!(value instanceof Instance)) {
nextCouldBeInstance = true;
if(OWLUtil.hasOWLFullProfile(owlModel)) {
nextCouldBeSlot = true;
nextCouldBeCls = true;
errorMessage = "Individual, class or property expected";
}
else {
errorMessage = "Individual expected (in OWL DL)";
}
throw generateParseException();
}
}
else if(slot instanceof OWLDatatypeProperty && value instanceof Instance) {
errorMessage = "Datatype literal expected";
throw generateParseException();
}
if(create) {
return owlModel.createOWLHasValue(slot, value);
}
else {
return null;
}
}
}
Object OWLHasValueValueAndEOF() :
{
Object result;
}
{
result=OWLHasValueValue() <EOF>
{
return result;
}
}
Object OWLHasValueValue() :
{
Object result;
}
{
(
result=OWLHasValueValueString()
| result=OWLHasValueValueFloat()
| result=OWLHasValueValueInteger()
| result=OWLHasValueValueBooleanOrInstance()
)
{
return result;
}
}
String OWLHasValueValueString() :
{
Token token;
}
{
token=<STRING_LITERAL>
{
String str = token.image;
int len = str.length();
return str.substring(1, len - 1);
}
}
Float OWLHasValueValueFloat() :
{
Token token;
}
{
token=<FLOATING_POINT_LITERAL>
{
return Float.valueOf(token.image);
}
}
Integer OWLHasValueValueInteger() :
{
Token token;
}
{
token=<INTEGER_LITERAL>
{
return Integer.valueOf(token.image);
}
}
Object OWLHasValueValueBooleanOrInstance() :
{
String id;
}
{
id=Identifier()
{
if(id.equals("true")) {
return Boolean.TRUE;
}
else
if(id.equals("false")) {
return Boolean.FALSE;
}
else {
RDFResource instance = ParserUtils.getRDFResourceFromName(owlModel, id);
if(instance == null) {
nextCouldBeInstance = true;
nextCouldBeSlot = true;
nextCouldBeCls = true;
errorMessage = "Instance or datatype literal expected";
throw generateParseException();
}
return instance;
}
}
}
int CardinalityValue() :
{
Token token;
}
{
token=<INTEGER_LITERAL>
{
int value = Integer.parseInt(token.image);
if(value >= 0) {
return value;
}
else {
throw generateParseException();
}
}
}
String Identifier() :
{
Token t;
}
{
t=<IDENTIFIER> {
return ParserUtils.dequoteIdentifier(t.image);
}
}
RDFSClass OWLEnumeratedClass() :
{
Collection values = new ArrayList();
String instanceText;
}
{
"{" (instanceText=Identifier()
{
Instance instance = (Instance) ParserUtils.getFrameByName(owlModel, instanceText);
if(OWLUtil.hasOWLDLProfile(owlModel) && (instance instanceof Cls || instance instanceof Slot)) {
instance = null;
}
if(instance == null) {
nextCouldBeInstance = true;
if(OWLUtil.hasOWLFullProfile(owlModel)) {
nextCouldBeCls = true;
nextCouldBeSlot = true;
errorMessage = "Name of an individual, class or property expected";
}
else {
errorMessage = "Name of an individual expected (in OWL DL)";
}
throw generateParseException();
}
values.add(instance);
}
)* "}"
{
checkFeatureSupported(OWLProfiles.Enumerated_Classes);
if(create) {
return owlModel.createOWLEnumeratedClass(values);
}
else {
return null;
}
}
}
OWLAllValuesFrom OWLAllValuesFrom(RDFProperty property) :
{
RDFSClass allCls;
Object valueType;
}
{
"*" {
checkFeatureSupported(OWLProfiles.AllValuesFrom_Restrictions);
}
(
valueType=DataType() {
if(valueType instanceof RDFSClass || valueType == ValueType.INSTANCE) {
if(property instanceof OWLDatatypeProperty) {
errorMessage = "owl:ObjectProperty or rdf:Property expected";
throw generateParseException();
}
if(create) {
return owlModel.createOWLAllValuesFrom(property, (RDFSClass)valueType);
}
else {
return null;
}
}
if(valueType == null) {
errorMessage = "XML Schema datatype expected";
throw generateParseException();
}
if(!(property instanceof OWLDatatypeProperty)) {
errorMessage = "owl:DatatypeProperty expected";
throw generateParseException();
}
if(create) {
if(valueType instanceof RDFSDatatype) {
return owlModel.createOWLAllValuesFrom(property, (RDFSDatatype)valueType);
}
else {
return owlModel.createOWLAllValuesFrom(property, (RDFSLiteral[])valueType);
}
}
else {
return null;
}
}
)
}
OWLSomeValuesFrom OWLSomeValuesFrom(RDFProperty property) :
{
RDFSClass someCls;
Object valueType;
}
{
"?" {
checkFeatureSupported(OWLProfiles.SomeValuesFrom_Restrictions);
}
(
valueType=DataType() {
if(valueType instanceof RDFSClass || valueType == ValueType.INSTANCE) {
if(property instanceof OWLDatatypeProperty) {
errorMessage = "owl:ObjectProperty or rdf:Property expected";
throw generateParseException();
}
if(create) {
return owlModel.createOWLSomeValuesFrom(property, (RDFSClass) valueType);
}
else {
return null;
}
}
else if(!(property instanceof OWLDatatypeProperty)) {
errorMessage = "owl:DatatypeProperty expected";
throw generateParseException();
}
if(valueType == null) {
errorMessage = "XML Schema datatype expected";
throw generateParseException();
}
if(create) {
if(valueType instanceof RDFSDatatype) {
return owlModel.createOWLSomeValuesFrom(property, (RDFSDatatype)valueType);
}
else {
return owlModel.createOWLSomeValuesFrom(property, (RDFSLiteral[])valueType);
}
}
else {
return null;
}
}
)
}
Object DataType() :
{
RDFSLiteral[] oneOfValues = null;
Object cl = null;
RDFSDatatype datatype;
boolean userDerived = false;
RDFProperty minProp = null;
RDFProperty maxProp = null;
String minVal = null;
String maxVal = null;
nextCouldBeDatatypeName = true;
}
{
(<ONE_OF> oneOfValues=OneOfValues()) { return oneOfValues; }
| (token=<DATATYPEID> {
String idName = ParserUtils.dequoteIdentifier(token.image);
String qName = datatypeNameChecker.getDatatypeQName(idName);
datatype = owlModel.getRDFSDatatypeByName(qName);
}
( // User defined part
(
(
(token=<OPENPAR>{minProp = XSPNames.getRDFProperty(owlModel, XSPNames.XSP_MIN_EXCLUSIVE);})
|
(token=<OPENSQPAR>{minProp=XSPNames.getRDFProperty(owlModel, XSPNames.XSP_MIN_INCLUSIVE);})
)
(((token=<INTEGER_LITERAL>{minVal = token.image;} | token=<FLOATING_POINT_LITERAL>{minVal = token.image;} | <UNBOUNDEDVAL>)))?
","
(((token=<INTEGER_LITERAL>{maxVal = token.image;} | token=<FLOATING_POINT_LITERAL>{maxVal = token.image;} | <UNBOUNDEDVAL>)))?
(
(token=<CLOSEPAR>{maxProp=XSPNames.getRDFProperty(owlModel, XSPNames.XSP_MAX_EXCLUSIVE);})
|
(token=<CLOSESQPAR>{maxProp=XSPNames.getRDFProperty(owlModel, XSPNames.XSP_MAX_INCLUSIVE);})
)
){
userDerived = true;
//System.out.println("User defined:");
//System.out.println("Min prop: " + minProp);
//System.out.println("Max prop: " + maxProp);
//System.out.println("Min val: " + minVal);
//System.out.println("Max val: " + maxVal);
})?
) {
if(userDerived == false) {
return datatype;
}
else {
if(create) {
RDFSDatatype udd = owlModel.createRDFSDatatype(owlModel.getNextAnonymousResourceName());
udd.setPropertyValue(XSPNames.getRDFProperty(owlModel, XSPNames.XSP_BASE), datatype);
if(minProp != null && minVal != null) {
udd.setPropertyValue(minProp, owlModel.createRDFSLiteral(minVal, datatype));
}
if(maxProp != null && maxVal != null) {
udd.setPropertyValue(maxProp, owlModel.createRDFSLiteral(maxVal, datatype));
}
return udd;
}
else {
return datatype;
}
}
}
| (cl=OWLComplementClass())
{
if(create) {
return cl;
}
else {
return ValueType.INSTANCE;
}
}
}
RDFSLiteral[] OneOfValues() :
{
Collection result = new ArrayList();
Token token = null;
Object numberValue = null;
}
{
(
(token=<STRING_LITERAL>
{
String str = token.image;
int len = str.length();
result.add(owlModel.createRDFSLiteral(str.substring(1, len - 1)));
}) |
(numberValue=OWLHasValueValueInteger()
{
result.add(owlModel.createRDFSLiteral(numberValue));
}) |
(numberValue=OWLHasValueValueFloat()
{
result.add(owlModel.createRDFSLiteral(numberValue));
})
)* "}" { return (RDFSLiteral[]) result.toArray(new RDFSLiteral[0]); }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -