Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Populate model with values stored written in a file
Populate model with values stored written in a file [message #1777385] Wed, 29 November 2017 05:35 Go to next message
Qamar uz Zaman is currently offline Qamar uz ZamanFriend
Messages: 10
Registered: November 2017
Junior Member
Hello,
Is it possible to populate a model represented, with .model extension in an Epsilon project, with the values written in a text file and also write the target model including its field values to a text file?
Re: Populate model with values stored written in a file [message #1777428 is a reply to message #1777385] Wed, 29 November 2017 10:41 Go to previous messageGo to next message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 240
Registered: October 2009
Location: Mexico
Senior Member

Hello,

I guess it depends on what format is the text file... for "standard" formats such as CSV, JSON, YAML, etc., you can use one of the existing EMC drivers to use the text file as a model then you could write en EOL/ETL script to correctly populate the .model (EMF) with the information. Of course this can be done in the other direction too.
If the text file is in some bespoke format then you will need to either write the appropriate EMC driver or write a parser in Java that uses Reflective EMF to "copy" the values from the text file to the EMF model.

Cheers,


Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Re: Populate model with values stored written in a file [message #1777446 is a reply to message #1777428] Wed, 29 November 2017 12:37 Go to previous messageGo to next message
Qamar uz Zaman is currently offline Qamar uz ZamanFriend
Messages: 10
Registered: November 2017
Junior Member
Thank you.
Can you suggest an example code to use .EMC driver for populating a .model from CSV text file and vice versa.
Re: Populate model with values stored written in a file [message #1777551 is a reply to message #1777446] Thu, 30 November 2017 09:53 Go to previous messageGo to next message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 240
Registered: October 2009
Location: Mexico
Senior Member

Hi,
I guess something like the following will work.

1. Create a simple EMF meta model using Emfatic[1], and generate the .ecore from it (right click->Generate Ecore Model)
@namespace(
	uri="http://example.org/epsilon/emc/csv/people.ecore",
	prefix="p")
package top;

class Person {
	id attr Integer ~id;
	attr String first_name;
	attr String last_name;
	attr String[*] movies;
}


2. Have some data in CSV format:
id,first_name,last_name,movies
604-78-8459,Ricoriki,Dwyr,Horror
272-41-1349,Norry,Halpin,Drama,Film-Noir,Thriller
844-07-0023,Matteo,Macer,Horror,Mystery,Thriller
429-41-4964,Kattie,Fysh,Comedy
378-90-9530,Link,Proffitt,Drama
811-26-0387,Rafferty,Sobieski,Horror
386-53-1139,Ernestine,Kringe,Drama
850-05-5333,Flossy,Mobberley,Comedy,Romance
605-52-9809,Tull,Ingerithec,Drama
580-79-7291,Derry,Laurisch,Drama,War
676-89-8860,Cosetta,Vlasov,Crime,Film-Noir,Thriller
748-10-2370,Lissa,Stanger,Action,Adventure,Thriller
164-18-3409,Giffie,Boards,Comedy
212-06-7778,Rabbi,Varran,Horror
628-02-3617,Olvan,Alabone,Action,Adventure,Sci-Fi,Thriller
318-48-3006,Constantino,Eyckelbeck,War
122-74-6759,Nickolas,Collard,Drama,Fantasy,Mystery
309-57-3090,Chere,Hurry,Drama
833-32-9040,Mattie,Hamon,Drama
101-82-2564,Hew,Goble,Comedy


3. A simple ETL transformation that copies the fields from CSV to EMF. Here I use the fact that the CSV file has headers, if not you would have to use the "fields" field and access by index (example added in comments):
rule Row2Object
	transform r:csv!Row
	to p:emf!Person {
		p.first_name = r.first_name;          // p.first_name = r.fields.at(0); 
		p.last_name = r.last_name;
		p.movies.addAll(r.movies);
	}


4. In the launch configuration
a. Add a CSV model (need to tick the "Show all model types" box to see the CSV model type). I have used "csv" as the model name. This should probably be "Read on load" only. Also, check the "Known headers" box if you have headers (and the varargs box for this particular case).
b. Add an EMF model. Select your .model file (or type its path if it does not exist) and then add the .ecore meta model with the "Add file ..." button. I have used "emf" for the model name. This model should probably be "Store on Disposal" only.

5. Run the transformation. Your .model file should be populated.

Voila!

(I will be adding this example to the examples projects in due time if you will like to try it out).



[1] https://www.eclipse.org/emfatic/


Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Re: Populate model with values stored written in a file [message #1777602 is a reply to message #1777551] Thu, 30 November 2017 16:36 Go to previous message
Qamar uz Zaman is currently offline Qamar uz ZamanFriend
Messages: 10
Registered: November 2017
Junior Member
Thank you. This works fine.
Previous Topic:ETL
Next Topic:Execution time for ETL transformation
Goto Forum:
  


Current Time: Fri Mar 29 11:09:00 GMT 2024

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

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

Back to the top