Representing QVT-Operational transformations in XML, JSON or or any other serialized format - data-modeling

I have a requirement where I need to parse the transformations defined in the QVT-Operational file.
I need some way to represent the QVT-Operational transformations in a json, xml or any other serialized format.
In model to model transformation performed using operational QVT in eclipse, I am able to generate a trace file in XML format. The trace file provides details on which element in the source model is mapped to which element in the target model but I also require the transformation logic. So is there any way to either convert the QVT-operational file to xml(or any serialized format) or get transformation details in the trace file ?

Interactively there is no support since use of the unstable internal *.qvtox representation is not encouraged.
However programmatically you may save the compiled Resource to a *.qvtox XMI file and load it again later, provided you use a compatible OCL+QVTo release.
See also https://www.eclipse.org/forums/index.php/mv/msg/1109554/1848331/#msg_1848331

Related

How to parse JSON-LD feed using dotNetRDF in C#

I'm trying to consume a json-ld formatted endpoint in a dotnet app.
I've not come across this format before but most of the examples are for JavaScript.
I've tried a couple of libraries and simply failing because there is so little reference.
I've loaded the contents of the endpoint into memory, now I want to see how best to traverse the nodes, but I can't take the contents and do anything with them.
The simplest example OUGHT to look something like:
JsonLdParser parser = new JsonLdParser();
parser.Load(contentsfromuri)
However, the above requires you to have an IRdfReader declared, which cannot be instantiated as its an abstract class.
You'll find the dotNetRDF documentation all at https://github.com/dotnetrdf/dotnetrdf/wiki. There are some examples of parsing RDF data from various sources at https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Reading-RDF. In RDF there are syntaxes that only ever serialize a single graph and syntaxes that can serialize multiple graphs - JSON-LD is one of the latter, so you need to also read the section on Store Readers.
The following examples all show loading the data into an in-memory store.
If your content source is "well-behaved" (sends back the right sort of Content-Type headers, or has the expected file name suffix if it is a local file), then loading the data can be as simple as creating a new in-memory graph and calling its Load method:
var store = new TripleStore();
# This is a convenience wrapper that simply invokes UriLoader.Load()
store.LoadFromUri(contentSourceUri)
NOTE: This uses an extension method (as described at https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Extension-Methods) which is just a convenience wrapper around:
# Create the store
var store = new TripleStore();
# UriLoader will make an HTTP request and parse the response,
# selecting the parser to be used based on the Content-Type header returned.
UriLoader.Load(store, contentSourceUri);
If you are parsing from a string that you have already retrieved, or if you need to be explicit about the parser instance to use (this may be the case if you want to pass some options to the parser when you create it for example), then you need a slightly more verbose approach:
var store = new TripleStore();
# Create the parser (we can pass in options here if needed)
var parser = new JsonLdParser();
# Wrap the string content in a StringReader and pass the target graph and the reader
parser.Load(store, new StringReader(contentsFromUri));
One final thing to note as you specifically refer to JSON-LD. The parser is a conformant JSON-LD 1.0 parser but it's JSON-LD 1.1 support is based on an earlier draft of the spec. I'm currently working on updating the implementation and hope to have a new release that supports the JSON-LD 1.1 Proposed Recommendation in a few weeks.

How to change game data on the fly in a packaged UE4 project?

My question seems to be pretty straight forward but, I haven't been able to find any solutions to this online. I've looked at a number of different types of objects like DataTables and DataAssets only to realize they are for static data alone.
The goal of my project is to have data-driven configurable assets where we can choose different configurations for our different objects. I have been able to successfully pull JSON data down from the database at run-time but, I would like to save said data to something like a Data Asset or something similar that I can read and write to. So when we pull from said database later we only pull updates to our different configurations and not the entire database (every time at start-up).
On a side note: would this be possible/feasible using an .ini file or is this kind of thing considered too big for something like that (i.e 1000+ json objects)?
Any solutions to this problem would be greatly appreciated.
Like you say, DataTable isn't really usable here. You'll need to utilize UE4's various File IO API utilities.
Obtaining a Local Path
This function converts a path relative to your intended save directory, into one that's relative to the UE4 executable, which is the format expected throughout UE4's File IO.
//DataUtilities.cpp
FString DataUtilities::FullSavePath(const FString& SavePath) {
return FPaths::Combine(FPaths::ProjectSavedDir(), SavePath);
}
"Campaign/profile1.json" as input would result in something like:
"<game.exe>/game/Saved/Campaign/profile1.json".
Before you write anything locally, you should find the appropriate place to do it. Using ProjectSaveDir() results in saving files to <your_game.exe>/your_game/Saved/ in packaged builds, or in your project's Saved folder in development builds. Additionally, FPaths has other named Dir functions if ProjectSavedDir() doesn't suit your purpose.
Using FPaths::Combine to concatenate paths is less error-prone than trying to append strings with '/'.
Storing generated JSON Text Data on Disk
I'll assume you have a valid JSON-filled FString (as opposed to a FJSONObject), since generating valid JSON is fairly trivial.
You could just try to write directly to the location of the full path given by the above function, but if the directory tree to it doesn't exist (i.e., first-run), it'll fail. So, to generate that path tree, there's some path processing and PlatformFile usage.
//DataUtilities.cpp
void DataUtilities::WriteSaveFile(const FString& SavePath, const FString& Data) {
auto FullPath = FullSavePath(SavePath);
FString PathPart, Disregard;
FPaths::Split(FullPath, PathPart, Disregard, Disregard);
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
if (PlaftormFile.CreateDirectoryTree(*PathPart)){
FFileHelper::SaveStringToFile(Data, *FullPath);
}
}
If you're unsure what any of this does, read up on FPaths and FPlatformFileManager in the documentation section below.
As for generating a JSON string: Instead of using the Json module's DOM, I generate JSON strings directly from my FStructs when needed, so I don't have experience with using the Json module's serialization functionality. This answer seems to cover that pretty well, however, if you go that route.
Pulling Textual Data off the Disk
// DataUtilities.cpp
bool DataUtilities::SaveFileExists(const FString& SavePath) {
return IFileManager::Get().FileExists(*FullSavePath(SavePath));
}
FString DataUtilities::ReadSaveFile(const FString& SavePath) {
FString Contents;
if(SaveFileExists(SavePath)) {
FFileHelper::LoadFileToString(Contents, *FullSavePath(SavePath));
}
return Contents;
}
As is fairly obvious, this only works for string or string-like data, of which JSON qualifies.
You could consolidate SaveFileExists into ReadSaveFile, but I found benefit in having a simple "does-this-exist" probe for other methods. YMMV.
I assume if you're already pulling JSON off a server, you have a means of deserializing it into some form of traversable container. If you don't, this is an example from the UE4 Answer Hub of using the Json module to do so.
Relevant Documentation
FFileHelper
FFileHelper::LoadFileToString
FFileHelper::SaveStringToFile
IFileManager
FPlatformFileManager
FPaths
UE4 Json.h (which you may already be using)
To address your side note: I would suggest using an extension that matches the type of content saved, if for nothing other than clarity of intention. I.e., descriptive_name.json for files containing JSON. If you know ahead of time that you will be reading/needing all hundreds or thousands of JSON objects at once, it would likely be better to group as many as possible into fewer files, to minimize overhead.

media files converter plugin/component in CakePHP

I am trying to develop a plugin/component that can change the media file format from one to another. Specifically, I need it to convert the "tiff" file to array/single copy of "jpg" image file.
Kindly guide, how I can implement it or is there any kind of tutorial link from where either I can download it or take some help to develop it. Thanks in advance.
We did this in our CMS (built on CakePHP 1.2; sorry if there are any significant discrepancies I'm not aware of) using a behaviour. That makes the controller logic very easy (in fact we use a baked controller without any modification at all).
Unfortunately TIFF isn't a supported file format in GD (the default image manipulation library in PHP). You'll need to use ImageMagick or an equivalent tool to do the actual conversion itself, but the logic for implementing it in your CakePHP project won't be any different to what I describe here.
The behaviour (in our case) was used to generate images as thumbnails as well as page resolution and to convert the uploaded file format into JPEG.
In its beforeSave() method it checked that data was specified (and that there was no error), and then pulled the tmp_name value from the posted data (and removed the posted data object).
In its afterSave() method, it actually performed the image conversion task itself (putting the generated images in the expected location on disk), then updated any foreign keys on extended models with the uploaded image's ID. We do this in the afterSave() operation so we have a database ID to use to name the files on disk.
In its afterDelete() method we unlink the files on disk.
Using the behaviour in the model is as simple as telling the model (where ContentImage is the name of the behaviour):
var $actsAs = array('ContentImage');
Although we also use the model to define the output directory since we had a few models that implemented the behaviour, and it felt like the right thing to do, e.g. in the model:
function getThumbnailDir() {
return WWW_ROOT.'img'.DS.'upload'.DS.'thumb';
}
and in the behaviour itself the output path becomes:
$Model->getThumbnailDir().DS.$Model->id.'.jpg'

Java library for extracting metadata

I have a binary file which has an ASCII metadata header. The elements are of the form "tag = value". Do you know of any Java libraries that will simplify extraction of this metadata.
Yes, you can use Properties. Its load and store methods use a format very similar to the one you described.

dynamic map managment in google earth

My goal is to display various shapes(polygons, points, linestring) on google maps by using data entered into a Postgis database dynamically(i mean by that we can see modifications in the map in real time).
I was looking for a way to do this that used the spatial structure already provided in postgis(already designating if shape is a linestring or polygon, etc) instead of parsing out the coordinates and then re-entering spatial structure in google maps. I saw that google maps api is now compatible with kml data formats. And then I read that i have to convert postgis data to kml format.
I've done some reading in the forums about the actual process of converting postgis data to kml via FWTools, but didn't see anything that would help me. I'm new to kml but am familiar with postgis and perl and PHP. Is there a tutorial for the process of converting postgis data to kml? Where can I get started? Thanks for any help
You can use PostGIS to convert to KML directly:
SELECT ST_AsKML(geometry) from MyTable;
ST_AsKML is one of several output formats, including WKT, GML, GeoJSON, etc.
To show dynamic data in Google Earth, a common pattern is to use KML with a NetworkLink element. Have the link's viewRefreshMode equal to onStop and Google Earth will make requests (to a URL served by PHP, presumably) with bounding box parameters attached. Use the bounding box to query features in the PostGIS database, and return results as kml. This is great if you have lots and lots of features, but only want to retrieve those in the region the user is looking at.
Depending on the complexity of your application, you may also want to look at GeoDjango. (Familiarity with PostGIS is a big head start!)
You can get a textual representation of the spatial data from a Postgres DB using a text conversion function, like
SELECT AsText(MyGemoetry) from MyTable
then you parse the string, create your objects using various API functions - depending on the PostGIS geometry type - and append these object to the main GE plugin object in a DOM like way.
If you are familiar with JavaScript and have a fundamental knowledge of XML, a good start is http://code.google.com/apis/earth/documentation/reference/
Don't forget to specify unique ID's to your objects so you can find them later to drop/modify.
Maybe you can get some inspirations here, display the linked "locator.js" file and look at function PaintSubField(Coord) ... this is another way, bit crude but effective, avoiding to mess around with too many individual parent/child objects and structures
You also may want to consult sample applications and use the code playground for "rapid prototyping"
re "realtime" you need at least an event that you can link your generation/redraw routines to.
Good luck
MikeD

Resources