Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Extending OCL standard library with function returning Sequence(T)
Extending OCL standard library with function returning Sequence(T) [message #490605] Fri, 09 October 2009 11:25 Go to next message
Pierre Gaufillet is currently offline Pierre Gaufillet
Messages: 30
Registered: July 2009
Member
Hi !

Working on OCL extensions for TOPCASED, I added a regex function returning a Sequence of matched groups. This function is declared in my oclstdlib.ecore model as:
in String_Class: regexMatch(pattern: EString) : Sequence(T)

and implemented in the evaluation environment as:
public Object callOperation(EOperation operation, int opcode, Object source, Object[] args) throws IllegalArgumentException
    {
        if (operation.getEAnnotation("OclsamEnvironment") != null)
        {
            if ("regexMatch".equals(operation.getName()))
            {
                Pattern pattern = Pattern.compile((String) args[0]);
                String sourceArg = new String();
                Matcher matcher = null;
                List<String> result = new ArrayList<String>();

                if (source != null)
                {
                    sourceArg = (String) source;
                }
                matcher = pattern.matcher(sourceArg);

                if (matcher.matches())
                {
                    for (int i = 1; i <= matcher.groupCount(); i++)
                    {
                        result.add(matcher.group(i));
                    }
                }

                return result;
            }
[...]

It runs quite nicely but functions with a 'T' parameter can not be applied on the result.

context System inv rule: self.name.regexMatch('(\w+)')->size()

is ok but:
context System inv rule: self.name.regexMatch('(\w+)')->include('system')

raises the error: Cannot find operation (indexOf(String)) for the type (Sequence(T))

Does somebody know why and how to avoid it ?
Re: Extending OCL standard library with function returning Sequence(T) [message #490836 is a reply to message #490605] Sun, 11 October 2009 18:19 Go to previous messageGo to next message
Eclipse User
Originally posted by: Nicolas.F.Rouquette.jpl.nasa.gov

The function declaration returns a generic Sequence(T) without constraining
T in any way. Since the type checker can't tell a-priori what T is; it can't
figure out if Sequence(T)->indexOf(String) is well-typed either.

The function definition isn't generic at all as it returns
Sequence(String_Class).

Have you tried a non-generic declaration like this:

in String_Class: regexMatch(pattern: EString) : Sequence(String_Class)

- Nicolas.

On 10/9/09 4:25 AM, in article han6j2$foj$1@build.eclipse.org, "Pierre
Gaufillet" <pierre.gaufillet@airbus.com> wrote:

> Hi !
>
> Working on OCL extensions for TOPCASED, I added a regex function returning a
> Sequence of matched groups. This function is declared in my oclstdlib.ecore
> model as:
>
> in String_Class: regexMatch(pattern: EString) : Sequence(T)
>
> and implemented in the evaluation environment as:
>
> public Object callOperation(EOperation operation, int opcode, Object source,
> Object[] args) throws IllegalArgumentException
> {
> if (operation.getEAnnotation("OclsamEnvironment") != null)
> {
> if ("regexMatch".equals(operation.getName()))
> {
> Pattern pattern = Pattern.compile((String) args[0]);
> String sourceArg = new String();
> Matcher matcher = null;
> List<String> result = new ArrayList<String>();
>
> if (source != null)
> {
> sourceArg = (String) source;
> }
> matcher = pattern.matcher(sourceArg);
>
> if (matcher.matches())
> {
> for (int i = 1; i <= matcher.groupCount(); i++)
> {
> result.add(matcher.group(i));
> }
> }
>
> return result;
> }
> [...]
>
> It runs quite nicely but functions with a 'T' parameter can not be applied on
> the result.
>
> context System inv rule: self.name.regexMatch('(\w+)')->size()
> is ok but:
> context System inv rule: self.name.regexMatch('(\w+)')->include('system')
> raises the error: Cannot find operation (indexOf(String)) for the type
> (Sequence(T))
>
> Does somebody know why and how to avoid it ?
>
Re: Extending OCL standard library with function returning Sequence(T) [message #490851 is a reply to message #490605] Sun, 11 October 2009 20:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4095
Registered: July 2009
Senior Member
Hi Pierre

Provision of regex has been raised as OCL Issue 10561 and was
enthusiastically received. We just need a specification and a
prototype. If you have anything that you can contribute we may
be able to make some progress and have regex for OCL 2.3.

Regards

Ed Willink

Pierre Gaufillet wrote:
> Hi !
>
> Working on OCL extensions for TOPCASED, I added a regex function
> returning a Sequence of matched groups. This function is declared in my
> oclstdlib.ecore model as:
>
> in String_Class: regexMatch(pattern: EString) : Sequence(T)
>
> and implemented in the evaluation environment as:
>
> public Object callOperation(EOperation operation, int opcode, Object
> source, Object[] args) throws IllegalArgumentException
> {
> if (operation.getEAnnotation("OclsamEnvironment") != null)
> {
> if ("regexMatch".equals(operation.getName()))
> {
> Pattern pattern = Pattern.compile((String) args[0]);
> String sourceArg = new String();
> Matcher matcher = null;
> List<String> result = new ArrayList<String>();
>
> if (source != null)
> {
> sourceArg = (String) source;
> }
> matcher = pattern.matcher(sourceArg);
>
> if (matcher.matches())
> {
> for (int i = 1; i <= matcher.groupCount(); i++)
> {
> result.add(matcher.group(i));
> }
> }
>
> return result;
> }
> [...]
>
> It runs quite nicely but functions with a 'T' parameter can not be
> applied on the result.
>
> context System inv rule: self.name.regexMatch('(\w+)')->size()
> is ok but:
> context System inv rule: self.name.regexMatch('(\w+)')->include('system')
> raises the error: Cannot find operation (indexOf(String)) for the type
> (Sequence(T))
>
> Does somebody know why and how to avoid it ?
>
Re: Extending OCL standard library with function returning Sequence(T) [message #490915 is a reply to message #490836] Mon, 12 October 2009 11:53 Go to previous messageGo to next message
Pierre Gaufillet is currently offline Pierre Gaufillet
Messages: 30
Registered: July 2009
Member
Thanks Nicolas !

It works far better Smile ! I added a EClassifier for Sequence(String_Class) in oclstdlib.ecore:

    <eClassifiers xsi:type="ecore:EClass" name="Sequence(String_Class)_Class">
      <eAnnotations source="http://www.eclipse.org/oclsam/stdlib/1.1" references="#/0/Sequence(String_Class)"/>
    </eClassifiers>
    <eClassifiers xsi:type="ocl.ecore:SequenceType" name="Sequence(String_Class)"
        instanceClassName="java.util.List" elementType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>


and modified regexMatch as you proposed:

     in String_Class: regexMatch(pattern: EString) : Sequence(String_Class)


Re: Extending OCL standard library with function returning Sequence(T) [message #490917 is a reply to message #490851] Mon, 12 October 2009 11:56 Go to previous messageGo to next message
Pierre Gaufillet is currently offline Pierre Gaufillet
Messages: 30
Registered: July 2009
Member
Hi Ed,

I'll be pleased to help.
Please send me an example of such a specification/prototype and I will complete it.

Quote:
Hi Pierre

Provision of regex has been raised as OCL Issue 10561 and was
enthusiastically received. We just need a specification and a
prototype. If you have anything that you can contribute we may
be able to make some progress and have regex for OCL 2.3.

Regards

Ed Willink
Re: Extending OCL standard library with function returning Sequence(T) [message #491012 is a reply to message #490917] Mon, 12 October 2009 19:25 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4095
Registered: July 2009
Senior Member
Hi Pierre

Thanks for the enthusiastic response.

The prototype is probably fairly easy. Java provides good regexp
functionality, that just needs invoking appropriately.

The original Issue 10561 was

"The Object Constraint Language (OCL) is an integral part of the Unified
Modeling Language (UML) and is often used separately as a general
constraint specification language in software development tools. For
example, OCL is incorporated in the Generic Modeling Environment (GME)
developed by the Institute of Software Integrated Systems (ISIS) of
Vanderbilt University (http://www.isis.vanderbilt.edu/default.asp The
GME implementation extends the OCL standard to include Regular
Expressions. A Regular Expression is a pattern that describes (or
matches) a set of strings where the pattern is itself a string and
conforms to a specific syntax. Regular Expressions are ideal for
expressing format constraints on OCL String values. Moreover, Regular
Expressions are widely used, familiar to many software developers and
complement the OCL’s already powerful constraint specification syntax.
Unfortunately, Regular Expressions are not currently supported in OCL
Version 2.0. Augmenting the OCL standard with Regular Expressions will
improve OCL’s constraint specification capabilities for String values
with a powerful, familiar notation and would also codify existing
practice as manifested in tools such as GME. Please consider the
inclusion of Regular Expression support in future releases of the Object
Constraint Language (OCL) specification."

The main task is to propose how OCL should be extended to support regex.
?? library functions, ?? new operators, ?? I haven't read the
GME reference so maybe they've solved it.

Once you have an elegant way to access regex you need to determine
how/if it reacts with other language features, e.g. regex of an Integer,
OrderedSet(String), Tuple, ... internationalisation, ..

Finally you (well someone) need to write the revised specification.
This requires some "replace .... by .... " instructions.

ftp://ftp.omg.org/pub/issue-attachments/14357/StringConcrete Syntax1.odt

is an example. The OCL spec is now an Open Office document, so use
of Open Office makes cut and paste easier.

[You don't have to do everything; if you get far enough you may motivate
someone else to finish off.]

Regards

Ed Willink



Pierre Gaufillet wrote:
> Hi Ed,
>
> I'll be pleased to help.
> Please send me an example of such a specification/prototype and I will
> complete it.
>
> Quote:
>> Hi Pierre
>>
>> Provision of regex has been raised as OCL Issue 10561 and was
>> enthusiastically received. We just need a specification and a
>> prototype. If you have anything that you can contribute we may
>> be able to make some progress and have regex for OCL 2.3.
>>
>> Regards
>>
>> Ed Willink
>
Previous Topic:LET and IN
Next Topic:Check for an existing reference
Goto Forum:
  


Current Time: Thu Oct 23 15:21:01 GMT 2014

Powered by FUDForum. Page generated in 0.03329 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software