Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ontouml2alloy #106

Open
wants to merge 24 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bc94668
Merge pull request #1 from OntoUML/development
fernandoam14 Mar 10, 2021
f2eb7fe
OntoUML 2.0 to Alloy Transformation
fernandoam14 May 13, 2021
41bf42b
Run result modified to three fields
fernandoam14 May 16, 2021
955086b
Added folder for ontouml2alloy tests
APantov Mar 23, 2023
2adee5a
Added helper class; added/fixed test cases
APantov Mar 24, 2023
868cfae
Added new test cases
APantov Mar 27, 2023
88eb8f5
More test cases added
APantov Mar 28, 2023
f8b1c47
class_functions fixing, added helper functions to helper.ts
APantov Apr 5, 2023
6161315
new helper function & class_functions adaptation
APantov Apr 5, 2023
8821619
empty name_normalization.test.ts,adapt other tests
APantov Apr 9, 2023
46be965
new test for name name_normalization, in dev
APantov Apr 13, 2023
ed8c011
normalize_name function & testing
APantov Apr 13, 2023
de8f43f
name_norm update & many other updates, fixes,TODOs
APantov Apr 27, 2023
66cf275
update generalization_set_functions
APantov Apr 27, 2023
065ac10
generalization & gen_set & helpers update
APantov May 3, 2023
c8d5a32
trim model implementation & testing
APantov May 8, 2023
00c411b
trim model implementation & testing
APantov May 8, 2023
0f81e3d
remove unnecessary checks
APantov May 9, 2023
ff309e4
a lot of minor updates
APantov May 17, 2023
85dafe6
relation test, fix minor things
APantov Jun 1, 2023
0b4ba79
update naming + tests
APantov Jun 18, 2023
b138ab3
property_functions test, relation_functions test
APantov Jul 5, 2023
7bc7ba7
minor fix,unsupp categorizer doesn't remove genSet
APantov Jul 5, 2023
1f1ea05
remove improper use of getAlias
APantov Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
class_functions fixing, added helper functions to helper.ts
  • Loading branch information
APantov committed Apr 5, 2023
commit f8b1c47264fa08ffd84355933d3038514237c35c
101 changes: 45 additions & 56 deletions __tests__/libs/ontouml2alloy/class_functions.test.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
import { Ontouml2Alloy } from '@libs/ontouml2alloy/index';
import { generateAlloy } from '@libs/ontouml2alloy/helper';
import { generateAlloy, generateFact, generateWorldAttribute, generateWorldFact } from '@libs/ontouml2alloy/helper';
import { Class, ClassStereotype, Relation, Package, Project, Property, OntoumlType, AggregationKind, stereotypeUtils, OntologicalNature} from '@libs/ontouml';
import { transformClass } from '@libs/ontouml2alloy/class_functions';

import { MultilingualText } from '@libs/ontouml';
import { resolve } from 'dns';


describe('Class Functions', () => {

describe('transformClass function', () => {

let project: Project;
let model: Package;
let transformer: Ontouml2Alloy;

// const eventClass = new Class({ name: new MultilingualText('Event'), stereotype: ClassStereotype.EVENT});
// const situationClass = new Class({ name: new MultilingualText('Situation'), stereotype: ClassStereotype.SITUATION });
// const datatypeClass = new Class({ name: new MultilingualText('DataType'), stereotype: ClassStereotype.DATATYPE });
// const enumerationClass = new Class({ name: new MultilingualText('Enumeration'), stereotype: ClassStereotype.ENUMERATION });
// const endurantClass = new Class({ name: new MultilingualText('Endurant'), isAbstract: false });
// const relatorClass = new Class({ name: new MultilingualText('Relator'), stereotype: ClassStereotype.RELATOR });
// const abstractClass = new Class({ name: new MultilingualText('AbstractClass'), isAbstract: true });

beforeEach(() => {
project = new Project();
model = project.createModel();
});

it('should return early if the class is an <<event>> or <<situation>>', () => {
// model.createKind('Happy Person');
it('should ignore classes if they are an <<event>>', () => {
const event = model.createEvent('Birthday');
expect(generateAlloy(model)).not.toContain('Birthday');
model.removeContent(event);
});

it('should ignore classes if they are a <<situation>>', () => {
model.createSituation('Hazard')
expect(generateAlloy(model)).not.toContain('Hazard');
// expect(transformer.getAlloyCode()[0]).toContain('HappyPerson: set exists:>Object');
});

// afterEach(() => {
Expand Down Expand Up @@ -69,67 +57,66 @@ describe('Class Functions', () => {
// // Assert
// //expect(() => ...).toThrow(); // call the function or class method with the input value and expect it to throw an error
// });


//add
it('should transform <<datatype>> class with attributes (complex datatype)', () => {
const _number = model.createDatatype('Number');
const complexDatatype = model.createDatatype('Date');
complexDatatype.createAttribute(_number, 'day');
complexDatatype.createAttribute(_number, 'month');
complexDatatype.createAttribute(_number, 'year');

const result = generateAlloy(model);
expect(result).toContain('sig Date in Datatype {');
expect(result).toContain('day: Number');
expect(result).toContain('month: Number');
expect(result).toContain('year: Number');
const factLines = ['Datatype = Number+Date','disjoint[Number,Date]'];

expect(result).toContain('sig Date in Datatype {\n day: Number\n}');
expect(result).toContain(generateFact('additionalDatatypeFacts',factLines));
}); //default multiplicy is "one" so "day: one Number" or "day: Number" should be the same

it('should NOT transform «datatype» class without attributes (primitive datatype)', () => {
it('should transform <<datatype>> class without attributes (primitive datatype)', () => {
const model = new Package();
model.createDatatype('Date');
const result = generateAlloy(model);

expect(result).not.toContain('sig Date in Datatype {');
}); //should there be such a requirement?
expect(result).toContain('sig Date in Datatype {');
expect(result).toContain(generateFact('additionalDatatypeFacts',['Datatype = Date']))
});

it('should transform <<enumeration>> class with attributes', () => {
const status = model.createEnumeration('Status');
status.createLiteral('Active');
status.createLiteral('Inactive');

const result = generateAlloy(model)
expect(result).toContain('enum Status {')
expect(result).toContain('Active, Inactive}')
expect(result).toContain('enum Status {\n Active, Inactive}')
});


it('should transform <<kind>> class', () => {
model.createKind('Person');
const expectedFacts =
'fact rigid {\n' +
' rigidity[Person,Object,exists]\n' +
'}'
;
expect(generateAlloy(model)).toContain(expectedFacts);
// console.log(generateAlloy(model));
//"exists:>Object in Group" ?
const result = generateAlloy(model);
expect(result).toContain(generateFact('rigid',['rigidity[Person,Object,exists]']));
expect(result).toContain(generateWorldAttribute('Person','Object'));
expect(result).toContain(generateWorldFact('Person','Object')); //to change
console.log(result);
});

it('should transform <<collective>> class { isExtensional=false }', () => {
it('should generate rigid fact for transforming <<collective>> class', () => {
model.createCollective('Group', false);
const result = generateAlloy(model);
const expectedFacts =
'fact rigid {\n' +
' rigidity[Group,Object,exists]\n' +
'}'
;
expect(result).toContain(expectedFacts);
expect(result).toContain(generateFact('rigid',['rigidity[Group,Object,exists]']));
});
//change member -> same thing -> isExtensional - false

it('should transform «collective» class { isExtensional=true }', () => {
model.createCollective('FixedGroup', true);
const result = generateAlloy(model);
// it('should generate fact to handle {isExtensional = True} for transforming <<collective>> class', () => {
// model.createCollective('FixedGroup', true);
// const result = generateAlloy(model);

});
// }); //TODO


// it('should generate fact to handle {isExtensional = False} for transforming <<collective>> class', () => {
// model.createCollective('FixedGroup', true);
// const result = generateAlloy(model);

// });

it('should transform «quantity» class', () => {
model.createQuantity('Wine');
Expand Down Expand Up @@ -175,14 +162,15 @@ describe('Class Functions', () => {
expect(result).toContain(expectedFacts);
});

it('should transform «abstract» class', () => {
const model = new Package();
model.createAbstract('Goal');
// it('should transform «abstract» class', () => {
// const model = new Package();
// model.createAbstract('Goal');

const result = generateAlloy(model);
// const result = generateAlloy(model);

// expect(result).toContain('');
// }); //TODO

expect(result).toContain(''); // to be figured out what needs to happen
});

it('should transform «mode» class { allowed=[intrinsic-mode] }', () => {
model.createIntrinsicMode('Skill');
Expand Down Expand Up @@ -221,10 +209,11 @@ describe('Class Functions', () => {
});

it('should transform «roleMixin» class', () => {
model.createRoleMixin('Customer');
model.createRoleMixin('Customer',);
const result = generateAlloy(model);

expect(result).toContain('');
console.log(result);
});

it('should transform «phaseMixin» class', () => {
Expand Down
6 changes: 6 additions & 0 deletions __tests__/libs/ontouml2alloy/generalization_functions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Generalization } from '@libs/ontouml';
import { Ontouml2Alloy } from '@libs/ontouml2alloy/index';
import { getNameNoSpaces } from '@libs/ontouml2alloy/util';
import { generateAlloy } from '@libs/ontouml2alloy/helper';
import { Package } from '@libs/ontouml';

22 changes: 21 additions & 1 deletion src/libs/ontouml2alloy/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Package, Project } from '@libs/ontouml';
import { Ontouml2Alloy } from '@libs/ontouml2alloy/index';
import { String } from 'lodash';

//returns the main module of a generated Alloy transformation
export function generateAlloy(modelOrProject: Package | Project): string {
Expand All @@ -13,4 +14,23 @@ export function generateAlloy(modelOrProject: Package | Project): string {
ontouml2alloy.transform();

return ontouml2alloy.getAlloyCode()[0];
}
}

export function generateFact(factName: string, factLines: string[]): string {
let result = `fact ${factName} {\n`;
for (const line of factLines) {
result += ` ${line}\n`;
}
result += '}';
return result;
}

export function generateWorldAttribute(className: string, classNature: string): string{
let result = className + ': set exists:>' + classNature;
return result;
}

export function generateWorldFact(className: string, classNature: string): string{
let result = '{\n exists:>' + classNature + ' in ' + className + '\n}';
return result;
} //change for multiple
8 changes: 8 additions & 0 deletions src/libs/ontouml2alloy/ontouml-js.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "../../.."
}
],
"settings": {}
}