in

The ORM Foundation

Get the facts!

Fact Model Data Extraction

Last post 06-22-2014 15:25 by Matthew Curland. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 06-12-2014 10:16

    Fact Model Data Extraction

     Hello all,

     I'm am new to ORM language and i am currently developing  an adaptation for a reference ontology building methodology using different fact models as  information data  input. I have been exploring the NORMA tool and so i was wondering if there is any way to programmatically manipulate these fact models  (edition & querying), API's or any type of solution to extract the fact model data (terms & relations) without resorting to editing tools.

     Thank you :)

     Pedro Andrade 

  • 06-12-2014 12:06 In reply to

    Re: Fact Model Data Extraction

    Hello Pedro,

    That is a very open-ended question. The NORMA tool is built as a set of extensions--the only thing special about the ORM and ORMDiagram extensions is that you can't turn them off--so anything thing you see in the tool can be programmatically accessed by writing your own extension, which will load you into the designer. The other options are to create a generator, or to load the model using your own program (allowed on a machine where NORMA can open in VS) and directly reading/manipulating the model.

    Of these options, creating a generator is by far the easiest thing to do. All of the NORMA generators are either pure XSLT or combine some extension implementation (to get additional elements in the .ORM file) which is then processed with XSLT. Generators are fairly straightforward to install, although the installation point is well hidden in the NORMA sources. If you look at http://sourceforge.net/p/orm/code/HEAD/tree/trunk/Tools/ORMCustomTool/Install.bat you'll find an _AddXslORMGenerator macro that does the installation. This .bat file relies on http://sourceforge.net/p/orm/code/HEAD/tree/trunk/SetupEnvironment.bat to initialize the environment, which in turn relies on the TargetVisualStudioVersion environment variable (see a list of values at the top of SetupEnvironment.bat). You can trim this down for your needs and experiment extracting data without doing a full NORMA build (you can attach a debugger to a setup install of NORMA and use the code, but DO NOT build the project (F5 or anything like unto it) on top of a setup install).

    If you can provide some additional specifics on what you're trying to extract and what level of interaction you want inside the tool I can give you other information as well. 

    -Matt 

     

  • 06-14-2014 2:24 In reply to

    Re: Fact Model Data Extraction

      Hi Matt, 

     Than you for the quick reply :)

     The idea of the project is to develop a methodology that gets "x" fact models, extracts the terminology/fact types in order to construct a glossary, defines  a taxonomy and later, with the semantic mismatches detected, constructs a reference model, like an ontology.

     What i want is to find a way to load these fact models in my java/c# code, in order to programmatically manipulate then, extract the terminology and the  relations that define each model. Perhaps if i generate a Plix.

     Regards,

     Pedro 

  • 06-14-2014 9:59 In reply to

    Re: Fact Model Data Extraction

    Hi Pedro,

    C# makes it easy. Plix is used to generate code that is a physical mapping of the model. The result is not the model itself, so is probably not what you're after.

    • Add a project reference to the ORMSolutions.ORMArchitect.Core.VS20XX.dll assembly that matches your VS version (either in the GAC or in your NORMA installation at PROGRAMFILES[x86]\ORM Solutions\ORM Architect for Visual Studio 20XX\bin directory).
    • Add a project reference to the Microsoft.VisualStudio.Modeling.Sdk.dll version that matches your VS year (you can see the number looking at what the TargetDslToolsAssemblyVersion is set to in the SetupEnvironment.bat file I pointed you at yesterday. (The first reference might pull this in automatically when you build.)
    • Add a few using lines to make this easier:

    using Microsoft.VisualStudio.Modeling;
    using ORMSolutions.ORMArchitect.Core.Load;
    using ORMSolutions.ORMArchitect.Core.ObjectModel;
     
    • Create a ModelLoader:
    ModelLoader loader = new ModelLoader(
    // VS2005:@"Software\Microsoft\VisualStudio\8.0\ORM Solutions\Natural ORM Architect\Extensions"
    // VS2008:@"Software\Microsoft\VisualStudio\9.0\ORM Solutions\Natural ORM Architect\Extensions"
    // VS2010:@"Software\ORM Solutions\Natural ORM Architect for Visual Studio 2010\Designer\Extensions"
    // VS2012 and 2013 similar to 2010 
    new ExtensionLoader(ExtensionModelData.LoadFromRegistry(@"Software\Microsoft\VisualStudio\8.0\ORM Solutions\Natural ORM Architect\Extensions", null, null)));
     
    • Load your file into a Store object (I'll let you figure out how to get your own STREAM from an .orm file). 
    Store store;
    using (STREAM)
    store = loader.Load(stream);
    • Your model is now in the Store object, you can explore to your hearts content. Each Store will contain one ORMModel.
    foreach (ORMModel model in store.ElementDirectory.FindElements<ORMModel>())
    {
    ...
    }
     
    -Matt 
  • 06-19-2014 14:48 In reply to

    Re: Fact Model Data Extraction

    Hi Matt,

    Once again, thank you for your time and assistance! :D

    My main objective is to manipulate/edit a ORM model (file). An example would be: capture all the fact types from the model.

    Thus I need help in the following:

    I need to build a project (could be in c# or JAVA) that is able to open a ORM file to load it to a programming object, which may be, if I understood correctly, the Store object that you mentioned in your previous message.

    Then, how can I build this project? What are the libraries (API) that I need to add to it in order be able to manipulate this ORM models?

    Sorry for my possible ignorance. Thanks in advanced!

    Pedro


  • 06-19-2014 16:10 In reply to

    Re: Fact Model Data Extraction

    Hello Pedro,

    You will need a C# project for a console or forms app (not a web application) that references the two libraries I mentioned before (the modeling SDK dll from Microsoft and the NORMA core dll). You'll probably want to lock the project platform to 32-bit instead of 'Any CPU' (the NORMA Dll itself handles any CPU, but some of the supporting Microsoft dlls it pulls in (specifically the graph object referenced by the diagramming dlls) are 32-bit only).

    For NORMA on VS 2005, the references look like this in the .csproj file:

    <Reference Include="Microsoft.VisualStudio.Modeling.Sdk, Version=8.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />

    <Reference Include="ORMSolutions.ORMArchitect.Core.VS2005, Version=1.0.0.0, Culture=neutral, PublicKeyToken=957d5b7d5e79e25f, processorArchitecture=MSIL" />

    The NORMA reference is obviously changed, but the .Sdk dll names change over time (not just the version). In general, the references look like this, where the replacement fields can be found in the SetupEnvironment.bat file (actually, scratch SetupEnvironmet.bat as it is doesn't have all of these settings, look instead in this file to expand the $(macros) shown below (v8.0=VS2005,v9.0=VS2008,v10.0=VS2010,v11.0=VS2012,v12.0=VS2013).
     
    <Reference Include="Microsoft.VisualStudio.Modeling.Sdk$(TargetDslToolsVersionSuffix), Version=$(TargetDslToolsAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
    <Reference Include="ORMSolutions.ORMArchitect.Core.$(TargetVisualStudioShortProductName), Version=1.0.0.0, Culture=neutral, PublicKeyToken=957d5b7d5e79e25f, processorArchitecture=MSIL">
     
    With these references you should be able to run the code I showed you. You'll just need a stream that references the .ORM file you're loading (it's an XML file, if that helps).
     
    -Matt 
     
     
  • 06-21-2014 14:58 In reply to

    Re: Fact Model Data Extraction

     Hi Matt,

     As you said, the .orm file is a XML. So knowing this, can't i simply explore the .orm with for  instance,  XPathNavigator ? like:  

     XPathDocument doc = new XPathDocument(ormPath);

     XPathNavigator navigator = document.CreateNavigator();

     string xml = navigator.OuterXml;

     navigator.MoveToChild(XPathNodeType.Element);

     string root = navigator.OuterXml;

    ModelLoader loader = new ModelLoader(new ExtensionLoader(ExtensionModelData.LoadFromRegistry(@"C:\Program Files (x86)\ORM Solutions\ORM Architect for Visual Studio 2010\bin\Extensions", null, null)));

    byte[ byteArray = Encoding.UTF8.GetBytes(root);

    MemoryStream stream = new MemoryStream(byteArray);  

    Store store;

    using (stream){

    store = loader.Load(stream);

    It seems i keep getting a NullException when loading the stream, can't figure it out why..

    Pedro

  • 06-21-2014 17:11 In reply to

    Re: Fact Model Data Extraction

    Hi Pedro,

    If you want to play with the XML I'd recommend doing it through XSLT and plugging in a generator, not through code. The two approaches offer much different experiences.

    You don't need XML at all for the model loader. In fact, it turns out there's a ModelLoader.Load(string fileName) overload that just takes the file name. Internally it does using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { return Load(fileStream); }, so it isn't really saving you much (and took minimal effort to write, which is probably why I forgot about it, sorry). However, it does show that you're working way too hard. You don't need XML at all, just a file name or file stream. All of the XML work is done for you internally.

    You switched the registry path I gave you to a file path, so there is no chance the ModelLoader will work. ExtensionModelData.LoadFromRegistry needs a registry path to where the NORMA extensions are listed, not a file path to where they are on disk. The registry information maps XML namespaces (listed in the root element of the .orm files) to extension assemblies. The assemblies are not all in one place, and just knowing the assembly list isn't enough information anyway.

    I've attached a project that loads a selected .orm file, lists the object types and fact types in combo boxes, and verbalizes them in a web browser control when the combos are changed. That should get you started (note there is no UI change on load, open a combo to see contents). The attached project is VS2010, which seems to match your system. Without the VerbalizationManager (which is cute, but probably not needed for your project), the crux of the code can be reduced to the following line:

    Store store = new ModelLoader(new ExtensionLoader(ExtensionModelData.LoadFromRegistry(@"Software\ORM Solutions\Natural ORM Architect for Visual Studio 2010\Designer\Extensions", null, null))).Load(FileDialog.FileName);

    -Matt 

     

  • 06-22-2014 13:21 In reply to

    Re: Fact Model Data Extraction

    Hi Matt,

    Indeed i had the registry path changed because i was having the "NullReferenceException" so i though i was giving the wrong path. I gave a try to the project you attached in the last post, it seems to give same exception i mentioned.

    Pedro 

  • 06-22-2014 15:25 In reply to

    Re: Fact Model Data Extraction

    Hi Pedro,

    Sorry, I tested this project on a 32-bit machine. It looks like I didn't set the platform target to 32-bit, which would give you this result running on a 64-bit OS.

    1. Click on the project node in the Solution Explorer window (second node, right below the one that says 'Solution...').
    2. Right click and choose Properties (or Alt-Enter)
    3. On the Build tab, look for Platform target in the General section.
    4. Change the target from Any CPU to x86
    5. Try to run the project again.
    If that doesn't fix it I'll need a call stack from the crash.
     
    -Matt

Page 1 of 1 (10 items)
© 2008-2014 The ORM Foundation: A UK not-for-profit organisation -------------- Terms of Service