Import Data with Data Load

Post Reply
ana.bautista
Posts: 14
Joined: 26 Jan 2011, 22:32

Hi everyone,

I'm trying to load some examples with data load, I've followed all the instructions on the file and successfully generate my create function, but when I execute it, an error pops up:

Code: Select all

Welcome to the Protégé shell
>>> execfile("C:\EssentialAM\Python\generateLoadCommand.py")
Generate Load Command: given a class name, generates python function to load a class
 
   generate(clsName)
   help() - this message
>>> generate("Technology_Product")
------ SAVE BELOW THIS LINE ------


def getInstance(clsName, name):

    if name is None:
        return None

    for curInstance in kb.getCls(clsName).getDirectInstances():
        curInsName = curInstance.getOwnSlotValue(kb.getSlot('name'))
        if ( curInsName == name ):
            return curInstance

    print "WARNING: unable to find class ", clsName, " with name: ", name
    return None



def getInstances(clsName, listOfNames):
    if listOfNames is None:
        return []
    return map(lambda(name): getInstance(clsName, name), listOfNames)


def createTechnology_Product(name , description , ImplementsTechnologyComponentsListOfInsName , MaintenanceCostFlt , TechnologyProductFunctionsOfferedListOfInsName , ExternalReferenceLinksListOfInsName , TechnologyProductArchitectureInsName , ProductLabelStr , TechnologyProductFamilyListOfInsName , ProductSupplierInsName ):

    cls = kb.getCls("Technology_Product")
    clsTagCode = 'TP::'
    insName = "%s%s" % (clsTagCode, name)
    ins = kb.getInstance(insName)
    if ins is None:
        print "Creating new instance: ", insName
        ins = kb.createInstance(insName, cls)
    else:
        print "Updating existing instance: ", insName

    ins.setOwnSlotValue(kb.getSlot("name"), name)
    ins.setOwnSlotValue(kb.getSlot("description"), description)
    ins.setOwnSlotValues(kb.getSlot("implements_technology_components"), getInstances("Technology_Provider_Role", ImplementsTechnologyComponentsListOfInsName))
    ins.setOwnSlotValue(kb.getSlot("maintenance_cost"), MaintenanceCostFlt)
    ins.setOwnSlotValues(kb.getSlot("technology_product_functions_offered"), getInstances("Technology_Function", TechnologyProductFunctionsOfferedListOfInsName))
    ins.setOwnSlotValues(kb.getSlot("external_reference_links"), getInstances("External_Reference_Link", ExternalReferenceLinksListOfInsName))
    ins.setOwnSlotValue(kb.getSlot("technology_product_architecture"), getInstance("Technology_Product_Architecture", TechnologyProductArchitectureInsName))
    ins.setOwnSlotValue(kb.getSlot("product_label"), ProductLabelStr)
    ins.setOwnSlotValues(kb.getSlot("technology_product_family"), getInstances("Product_Family", TechnologyProductFamilyListOfInsName))
    ins.setOwnSlotValue(kb.getSlot("supplier_technology_product"), getInstance("Supplier", ProductSupplierInsName))

    return ins
>>> execfile("C:\EssentialAM\Python\createTechnology_Product.py")
>>> createTechnology_Product("Visual Studio 2003","Application code development technology",["Software Development Language"],0.0,None,None,None,None,None,["Microsoft"])
Creating new instance:  TP::Visual Studio 2003
Traceback (innermost last):
  File "<string>", line 1, in ?
  File "C:\EssentialAM\Python\createTechnology_Product.py", line 36, in createTechnology_Product
  File "C:\EssentialAM\Python\createTechnology_Product.py", line 19, in getInstances
  File "C:\EssentialAM\Python\createTechnology_Product.py", line 19, in <lambda>
ValueError: unpack sequence too long
exception from Jython: Traceback (innermost last):
  File "<string>", line 1, in ?
  File "C:\EssentialAM\Python\createTechnology_Product.py", line 36, in createTechnology_Product
  File "C:\EssentialAM\Python\createTechnology_Product.py", line 19, in getInstances
  File "C:\EssentialAM\Python\createTechnology_Product.py", line 19, in <lambda>
ValueError: unpack sequence too long
: Traceback (innermost last):
  File "<string>", line 1, in ?
  File "C:\EssentialAM\Python\createTechnology_Product.py", line 36, in createTechnology_Product
  File "C:\EssentialAM\Python\createTechnology_Product.py", line 19, in getInstances
  File "C:\EssentialAM\Python\createTechnology_Product.py", line 19, in <lambda>
ValueError: unpack sequence too long
>>> 
Any thoughts on this???

Thanks!
Ana
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

Hi Ana,

I have a couple of thoughts about your code.

The first one is that if you have a look in the 'standardFunctions.txt' file that is included with the Integration Tab, there are a number of Python functions in there that will find you instances and create instances. You might find some of these useful.

Some documentation for what they do is available at the bottom of the Integration Transforms Tutorial

More specifically, the error seems to be in the lambda / map function in getInstances(). I'm not sure how that function is expected to behave but it looks like the python engine is not happy with this.

Note that the 'name' is the repository instance name rather than the name that you see on the forms in Protege. I think this might be causing trouble in 'createTechnology_Product()' as it looks like you are calling 'kb.getInstance(name)' using a name derived from the what's on the form. However, kb.getInstance(name) expects 'name' to be the instance ID.

Let me know if this moves you forward. Do have a look at the standardFunctions.txt. They might be of use but at the least will help show how we've used the Protege API to do imports etc. and how all these types of things work.

Jonathan
Essential Project Team
ana.bautista
Posts: 14
Joined: 26 Jan 2011, 22:32

Thanks for your quick reply Jonathan, I've been studying standardFunctions.txt and run some quick examples, for instance:

I would like to load some data into Technology_Product, for this I would be needing:

-Name of the product
-Description
-Product Supplier
-Product Label
-Implements Technology Components

For he first two I'll be needing some strings right? e.g.:

-Name: "vSphere"
-Description: "Nice Software blablabla..."

but for the other three things I would be needing some names already existing... some Instances... how or where do I find those names???

Kind regards,
Ana
ana.bautista
Posts: 14
Joined: 26 Jan 2011, 22:32

Well, I've managed to deal with the above, but now I want to load Technology_Product_Role:

-Name
-Description
-Role
-Technology Provider Playing Role

For name and description there's no issue, but for Technology Provider Playing Role, that uses Technology_Product associated with Supplier, when I try to load something with Data Load this other error pops out:

Code: Select all


>>> createSupplier("Test Supplier","Test Supplier Description",None,None,None,None)
Creating new instance:  S::Test Supplier
>>> createTechnology_Product("Test Product","Test Product Description",None,None,None,None,None,None,None,"Test Supplier")
Creating new instance:  TP::Test Product
>>> createTechnology_Product_Role("Temp??","Test Product Role Description","Search Engine","Test Product",None,None)
Creating new instance:  TPR::Temp??
Traceback (innermost last):
  File "<string>", line 1, in ?
  File "C:/EssentialAM/Python/createTechnology_Product_Role.py", line 37, in createTechnology_Product_Role
	at edu.stanford.smi.protege.model.framestore.ArgumentCheckingFrameStore.assertNotNull(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.ArgumentCheckingFrameStore.checkSlot(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.ArgumentCheckingFrameStore.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.ChangeMonitorFrameStore.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.cleandispatch.DefaultDispatch.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.cleandispatch.CleanDispatchFrameStore.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.FrameStoreAdapter.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.FrameStoreAdapter.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultKnowledgeBase.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultKnowledgeBase.setOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultFrame.setOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultFrame.setOwnSlotValue(Unknown Source)

	at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

	at java.lang.reflect.Method.invoke(Method.java:597)


java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: null slot
exception from Jython: Traceback (innermost last):
  File "<string>", line 1, in ?
  File "C:/EssentialAM/Python/createTechnology_Product_Role.py", line 37, in createTechnology_Product_Role
	at edu.stanford.smi.protege.model.framestore.ArgumentCheckingFrameStore.assertNotNull(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.ArgumentCheckingFrameStore.checkSlot(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.ArgumentCheckingFrameStore.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.ChangeMonitorFrameStore.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.cleandispatch.DefaultDispatch.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.cleandispatch.CleanDispatchFrameStore.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.FrameStoreAdapter.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.FrameStoreAdapter.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultKnowledgeBase.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultKnowledgeBase.setOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultFrame.setOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultFrame.setOwnSlotValue(Unknown Source)

	at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

	at java.lang.reflect.Method.invoke(Method.java:597)


java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: null slot
: Traceback (innermost last):
  File "<string>", line 1, in ?
  File "C:/EssentialAM/Python/createTechnology_Product_Role.py", line 37, in createTechnology_Product_Role
	at edu.stanford.smi.protege.model.framestore.ArgumentCheckingFrameStore.assertNotNull(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.ArgumentCheckingFrameStore.checkSlot(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.ArgumentCheckingFrameStore.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.ChangeMonitorFrameStore.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.cleandispatch.DefaultDispatch.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.cleandispatch.CleanDispatchFrameStore.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.FrameStoreAdapter.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.framestore.FrameStoreAdapter.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultKnowledgeBase.setDirectOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultKnowledgeBase.setOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultFrame.setOwnSlotValues(Unknown Source)

	at edu.stanford.smi.protege.model.DefaultFrame.setOwnSlotValue(Unknown Source)

	at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

	at java.lang.reflect.Method.invoke(Method.java:597)


java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: null slot



Any thoughts???
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

Hi Ana,

I was just about to reply to your previous post to mention the approach that I normally take. The most useful functions in the standardFunctions.txt library are the 'getEssentialInstanceNNN()' functions.

These all operate in much the same way, just use different searching patterns to find the specified instance. However, the important thing that these functions do is to return you a handle to the instance that you've asked for by name (not instance ID). The best bit is that if it can't find the specified instance, it creates a new one and returns that.

What this means is that you can, for example, ask for the Supplier that you need by it's name, e.g. 'Microsoft' and you will get the Supplier instance in return. As I said, if it's not already defined in the repository, then the function will create it for you.

This is very useful when defining relationships between instances during an import as it means that you can define a relationship even to things that have not yet been imported but when they are, that is your script gets to that instance, the correct instance (newly created earlier on) is returned to you so that you can complete its definition.

So, to create a new Technology_Product_Role, you can call getEssentialInstanceContains() for the Technology Product Role that you want, passing in the name that you've chosen in the 'instanceName' parameter (NOTE, this is the Name slot value, not the instance ID). When the instance has been returned by the function, you can set the description slot.
Next, you can use getEssentialInstanceContains() for the Role and then the Technology_Provider. Once you've got these you can pass the instances that you got back into set the role and technology provider slots on the new Technology Product Role.

The external repository definition and external repository reference parameters are used to keep a track of what ID this new Technology Product Role has in an external repository from which you've gathered the definition. This means that if you re-run the import, you can use these unique IDs from the data source to update instances that already exist in the Essential Repository - we can synchronise the repositories.

This might not be of interest, but it's worth creating a new External Repository definition and assigning each imported instance a unique ID so that you can track where and when each instance was imported.

Alternatively, you can have a look at the script code for the getEssentialInstanceNNN() functions to see how they use the Protege API to find/create instances.

One last thought. I notice that the code you've posted uses a lot of None values into the functions. The Protege API is implemented in Java and there's quite a bit of passing of objects that goes on. 'None' values often cause Null Pointer Exceptions in Java. I've had to add quite a bit of guard code to avoid calls being made when we would have an empty object.

Hope this helps

Jonathan
Essential Project Team
ana.bautista
Posts: 14
Joined: 26 Jan 2011, 22:32

Hi Jonathan,

So, for example, I will create one Technology_Product_Role like this:

Code: Select all

theInstance = getEssentialInstanceContains("Technology_Product_Role","","External Essential Repository","Test Product Role")
aSlotName = "description"
theInstance.setOwnSlotValue(kb.getSlot(aSlotName), "Blablablablabla...")
theRole = getEssentialInstanceContains("Technology_Component","","External Essential Repository","RDBMS")
aSlotName = ?
theInstance.setOwnSlotValue(kb.getSolt(aSlotName),theRole)
How can I get the Slot Name for the Technology_Component??
And how am I going to call theRole to be set into theInstance?

Thanks!
Ana
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

That's the sort of thing, yes.

I would be tempted to put some value in the second parameter of the getEssentialInstanceNNN() calls as these functions create instances of a meta class called External Instance Reference and if these don't have a name, they're going to get tricky to manage in the repository. You could get away with using the same name but I would suggest that you use some simple unique numbering approach, e.g. techology_prod_role_nn where nn is a unique number.

You've got your handle to the Technology Component (the Role) and then you can use the setSlot() function as follows:

setSlot(theInstance, "implementing_technology_component", theRole)

Then get the Technology Product and use this same function again to set the provider slot on the Technology Product Role:
theProduct= getEssentialInstanceContains(....)
setSlot(theInstance, "role_for_technology_provider", theProduct)

The slot names are documented on the website in the Meta Model Documentation section. I've just used that. Alternatively, if you're in Protege, have a look at the Class definitions (use the orange spy-glass button on the Class Browser) to see the names of the slots that you need.

And that will create a new Technology Product Role, also creating the Component and Product if they are not already defined in the repository.

Just to let you know, you should use the addIfNotThere() function for slots that take multiple instances. Our example here is just single cardinality slots, so setSlot() is just right.

Hope this gets things going!

Jonathan
Essential Project Team
ana.bautista
Posts: 14
Joined: 26 Jan 2011, 22:32

Hi Jonathan!

Yeap! It worked, I bet you've already noticed I'm a newbie on this, so thank you so much for your help, I'll probably bother you some other time... in the mean time I'll work with this...

Thank you so much ;)

Kind regards,
Ana B.
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

No problem, Ana!

Great to hear that you got it working and don't hesitate to post if you have any more questions.

The importing is a complex area because it also involves mapping to the meta model. The XML adapter (in Essential Integration Tab) is very much a toolkit to enable you to build the scripts that you need. The idea with that is that you define an XSL transform that transforms source XML to a Python script that uses the functions in StandardFunctions.txt

As a sneak preview, we've also been working on an Excel spreadsheet adapter. This also requires configuration (defined in XML) to map columns (and perhaps multiple columns) to build instances in Essential. Ultimately, this adapter generates and runs a script that uses the StandardFunctions.txt
This is coming soon.

The understanding that you've gained in working directly with your own integration script will be a great benefit.

Thanks for sticking with and posting the problems that you've had. Hopefully others will find these posts useful, too.

Let me know how things go with the integrations

Jonathan
Essential Project Team
ana.bautista
Posts: 14
Joined: 26 Jan 2011, 22:32

Hi Jonathan,

Well, I've managed to create my own function as you said, this is it:

createTechnology.py

Code: Select all

import java

from java.lang import Boolean

from java.lang import Float

defineExternalRepository("External Essential Repository", "External Essential Repository Source")

def createTechnology(productName, productDescription, productVersion, productSupplier, productRole, productStatus):
    theSupplier = getEssentialInstanceContains("Supplier","","External Essential Repository",productSupplier)
    theProduct = getEssentialInstanceContains("Technology_Product","","External Essential Repository",productName + " " + productVersion)
    setSlot(theProduct, "supplier_technology_product", theSupplier)
    aSlotName = "description"
    theProduct.setOwnSlotValue(kb.getSlot(aSlotName), productDescription)
    aSlotName = "version"
    theProduct.setOwnSlotValue(kb.getSlot(aSlotName), productVersion)
    theProductRole = getEssentialInstanceContains("Technology_Product_Role","","External Essential Repository", productSupplier + "::" + productName + "::as::" + productRole)
    theRole = getEssentialInstanceContains("Technology_Component","","External Essential Repository",productRole)
    theStatus = getEssentialInstanceContains("Lifecycle_Status","","External Essential Repository",productStatus)
    setSlot(theProductRole, "strategic_lifecycle_status", theStatus)
    setSlot(theProductRole, "implementing_technology_component", theRole)
    setSlot(theProductRole, "role_for_technology_provider", theProduct)

but when I run into protégé's console for many insertions, it just works for the first one, but the odd thing is that it prints that it actually updated something... ????

Code: Select all

Welcome to the Protégé shell
>>> execfile("C:/EssentialAM/RepositoryIntegration/standardFunctions.txt")
>>> execfile("C:/EssentialAM/Python/createTechnology.py")
>>> createTechnology("vSphere","Vmware vSphere is a Server Operating System","4.5","Vmware","Server Operating System","Under Planning")
createTechnology("Solaris","Oracle Corporation Solaris is a Server Operating System","10.0","Oracle Corporation","Server Operating System","Production")
createTechnology("Linux RHEL","RedHat Linux RHEL is a Server Operating System","5.3","RedHat","Server Operating System","Production")
createTechnology("Windows","Microsoft Windows is a Desktop Operating System","2003 x64","Microsoft","Desktop Operating System","Sunset")
createTechnology("AS/400","IBM AS/400 is a Server Operating System","5.1","IBM","Server Operating System","Sunset")
createTechnology("Classic ASP","Microsoft Classic ASP is a Software Development Language","1.0","Microsoft","Software Development Language","Retired")
createTechnology("WebSphere Portal","IBM WebSphere Portal is a Portal Server Platform","5.1","IBM","Portal Server Platform","Off Strategy")
Created new instance: , Essential name: Vmware
Created new instance: , Essential name: vSphere 4.5
Created new instance: , Essential name: Vmware::vSphere::as::Server Operating System
Updated instance: , Essential name: Server Operating System
Updated instance: , Essential name: Under Planning
Updated Instance: , Essential name: Oracle Corporation
Updated Instance: , Essential name: Solaris 10.0
Updated Instance: , Essential name: Oracle Corporation::Solaris::as::Server Operating System
Updated Instance: , Essential name: Server Operating System
Updated Instance: , Essential name: Production
Updated Instance: , Essential name: RedHat
Updated Instance: , Essential name: Linux RHEL 5.3
Updated Instance: , Essential name: RedHat::Linux RHEL::as::Server Operating System
Updated Instance: , Essential name: Server Operating System
Updated Instance: , Essential name: Production
Updated Instance: , Essential name: Microsoft
Updated Instance: , Essential name: Windows 2003 x64
Updated Instance: , Essential name: Microsoft::Windows::as::Desktop Operating System
Updated Instance: , Essential name: Desktop Operating System
Updated Instance: , Essential name: Sunset
Updated Instance: , Essential name: IBM
Updated Instance: , Essential name: AS/400 5.1
Updated Instance: , Essential name: IBM::AS/400::as::Server Operating System
Updated Instance: , Essential name: Server Operating System
Updated Instance: , Essential name: Sunset
Updated Instance: , Essential name: Microsoft
Updated Instance: , Essential name: Classic ASP 1.0
Updated Instance: , Essential name: Microsoft::Classic ASP::as::Software Development Language
Updated Instance: , Essential name: Software Development Language
Updated Instance: , Essential name: Retired
Updated Instance: , Essential name: IBM
Updated Instance: , Essential name: WebSphere Portal 5.1
Updated Instance: , Essential name: IBM::WebSphere Portal::as::Portal Server Platform
Updated Instance: , Essential name: Portal Server Platform
Updated Instance: , Essential name: Off Strategy
>>> 
weird huh?

and remembering the other post, when you said that you would probably put some value to the second parameter in the function getEssentialInstanceNNN(), is this has something to do with it???

Thanks in advance,
Ana :)
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

Yes, I'm pretty certain that the lack of an ID in that field that you've left blank is the cause of this.

The idea of that field is to use the repository ID of that element from the source repository. If you are using something like a CMDB, then I would recommend using the repository ID for each Technology Product that the CMDB has created. If you are using something simpler like a spreadsheet, then using a row ID and the spreadsheet/worksheet name as the repository name works just fine.
Doing this enables the getEssentialInstanceNNN() functions to find the right instance as accurately as possible.

In practice, it doesn't matter what values you have in here but I suspect that all will be well if you simply assign a unique number to each call of createTechnologyInstance() - you could even have createTechnologyInstance() do something about this automatically, e.g. use a hash of the current date/time?

Let me know if putting IDs in that field has resolved the problem

Jonathan
Essential Project Team
ana.bautista
Posts: 14
Joined: 26 Jan 2011, 22:32

Hi Jonathan!

Yeap, I've worked on the function all over the weekend and did exactly what you said, I put the date as the repository ID, so here's my function:

createTechnology.py

Code: Select all


import java

from java.lang import Boolean
from java.lang import Float
from java.text import SimpleDateFormat

defineExternalRepository("External Essential Repository", "External Essential Repository Source")

def createTechnology(productName, productDescription, productVersion, productSupplier, productRole, productStatus):
    dateFormat = SimpleDateFormat ( "ddMMyyyhhmmssSSS" )
    date = dateFormat.format(Date())
    theSupplier = getEssentialInstanceContains("Supplier",productSupplier + "_" + date,"External Essential Repository",productSupplier)
    theProduct = getEssentialInstanceContains("Technology_Product",productName + "_" + productVersion + "_" + date,"External Essential Repository",productName + " " + productVersion)
    setSlot(theProduct, "supplier_technology_product", theSupplier)
    aSlotName = "description"
    theProduct.setOwnSlotValue(kb.getSlot(aSlotName), productDescription)
    aSlotName = "version"
    theProduct.setOwnSlotValue(kb.getSlot(aSlotName), productVersion)
    theProductRole = getEssentialInstanceContains("Technology_Product_Role",productSupplier + "_" + productName + "_" + productRole + "_" + date,"External Essential Repository", productSupplier + "::" + productName + "::as::" + productRole)
    theRole = getEssentialInstanceContains("Technology_Component",productRole + "_" + date,"External Essential Repository",productRole)
    theStatus = getEssentialInstanceContains("Lifecycle_Status",productStatus + "_" + date,"External Essential Repository",productStatus)
    setSlot(theProductRole, "strategic_lifecycle_status", theStatus)
    setSlot(theProductRole, "implementing_technology_component", theRole)
    setSlot(theProductRole, "role_for_technology_provider", theProduct)


It works perfectly :D

Thank you so much!

I'll be doing a lot of these from now on :)

Ana B.
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

That's great to hear! Thanks for letting me know.

Apologies if I'm labouring the point but just as a bit of 'for future reference' if you find that you need to re-import these Technology Product Roles e.g. in response to changes made outside of Essential, then if you keep a track of the ID for each Technology Product Role, you can use this ID rather than matching the name in order to synchronise / update the instances in the Essential repository.
The name-based matching will also work but keep an eye on the number of instances of the External_Instance_Reference that you have in the Essential repository. You might want to clear them out once you have many more references than actual instances!

Of course, if this is a once-off import and you plan to make updates in Protege, then this is not required.

Keep in touch with how the imports are going

Jonathan
Essential Project Team
wktsugue
Posts: 7
Joined: 30 May 2011, 21:19

Hi Jonathan,
Do you have some useful version of your Excel adapter for importing data from Excel spredsheats into Essential Ontology?

Would we be able to use that excel adapter to import data into an customized extended Essential Ontology?

Very thanx.
Wilson.
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

Hi Wilson,

When it's complete, yes. As with the XML Adapter, the main task here is the semantic mapping from your source information to the Essential Meta Model - including any extensions or customisations that you might have needed to add.

In the case of spreadsheet, it's fundamentally about understanding what each column in the spreadsheet means.

As I mentioned in another post, we're still working on making this adapter much easier to use. We'll keep you posted!

Jonathan
Essential Project Team
FiRE2k7
Posts: 4
Joined: 16 Oct 2012, 07:31

I am having troubles with adding Business Processes.
Here is my log first:

Code: Select all

>>> generate("Business_Process")
------ SAVE BELOW THIS LINE ------


def getInstance(clsName, name):

    if name is None:
        return None

    for curInstance in kb.getCls(clsName).getDirectInstances():
        curInsName = curInstance.getOwnSlotValue(kb.getSlot('name'))
        if ( curInsName == name ):
            return curInstance

    print "WARNING: unable to find class ", clsName, " with name: ", name
    return None



def getInstances(clsName, listOfNames):
    if listOfNames is None:
        return []
    return map(lambda(name): getInstance(clsName, name), listOfNames)


def createBusiness_Process(name , description , BusinessProcessPerformedByBusinessRoleListOfInsName , SupportingApplicationFunctionsListOfInsName , DeletesInformationListOfInsName , CreatesInformationListOfInsName , SupportingApplication(Groups)ListOfInsName , ReadsInformationListOfInsName , StandardisationLevelInsName , UpdatesInformationListOfInsName , LifecycleStatusInsName , BusinessProcessOwnedByBusinessRoleListOfInsName , SupportingApplicationServicesListOfInsName , ImplementedByPhysicalBusinessProcessesListOfInsName , RealisesBusinessCapabilityInsName , BusinessProcessSupplierInsName , DefiningBusinessProcessFlowInsName ):

    cls = kb.getCls("Business_Process")
    clsTagCode = 'BP::'
    insName = "%s%s" % (clsTagCode, name)
    ins = kb.getInstance(insName)
    if ins is None:
        print "Creating new instance: ", insName
        ins = kb.createInstance(insName, cls)
    else:
        print "Updating existing instance: ", insName

    ins.setOwnSlotValue(kb.getSlot("name"), name)
    ins.setOwnSlotValue(kb.getSlot("description"), description)
    ins.setOwnSlotValues(kb.getSlot("business_process_performed_by_business_role"), getInstances("Business_Role", BusinessProcessPerformedByBusinessRoleListOfInsName))
    ins.setOwnSlotValues(kb.getSlot("bp_supported_by_app_fun"), getInstances("APP_FUN_TO_BUS_RELATION", SupportingApplicationFunctionsListOfInsName))
    ins.setOwnSlotValues(kb.getSlot("bus_process_type_deletes_information"), getInstances("Information_View", DeletesInformationListOfInsName))
    ins.setOwnSlotValues(kb.getSlot("bus_process_type_creates_information"), getInstances("Information_View", CreatesInformationListOfInsName))
    ins.setOwnSlotValues(kb.getSlot("bp_supported_by_app_app"), getInstances("APP_APP_TO_BUS_RELATION", SupportingApplication(Groups)ListOfInsName))
    ins.setOwnSlotValues(kb.getSlot("bus_process_type_reads_information"), getInstances("Information_View", ReadsInformationListOfInsName))
    ins.setOwnSlotValue(kb.getSlot("standardisation_level"), getInstance("Standardisation_Level", StandardisationLevelInsName))
    ins.setOwnSlotValues(kb.getSlot("bus_process_type_updates_information"), getInstances("Information_View", UpdatesInformationListOfInsName))
    ins.setOwnSlotValue(kb.getSlot("lifecycle_status_business"), getInstance("Lifecycle_Status", LifecycleStatusInsName))
    ins.setOwnSlotValues(kb.getSlot("business_process_owned_by_business_role"), getInstances("Business_Role", BusinessProcessOwnedByBusinessRoleListOfInsName))
    ins.setOwnSlotValues(kb.getSlot("bp_supported_by_app_svc"), getInstances("APP_SVC_TO_BUS_RELATION", SupportingApplicationServicesListOfInsName))
    ins.setOwnSlotValues(kb.getSlot("implemented_by_physical_business_processes"), getInstances("Physical_Process", ImplementedByPhysicalBusinessProcessesListOfInsName))
    ins.setOwnSlotValue(kb.getSlot("realises_business_capability"), getInstance("Business_Capability", RealisesBusinessCapabilityInsName))
    ins.setOwnSlotValue(kb.getSlot("business_process_supplier"), getInstance("Supplier", BusinessProcessSupplierInsName))
    ins.setOwnSlotValue(kb.getSlot("defining_business_process_flow"), getInstance("Business_Process_Flow", DefiningBusinessProcessFlowInsName))

    return ins
>>> execfile("C:\Dokumente und Einstellungen\Administrator\Desktop\py\createBusiness_Process.py")
Traceback (innermost last):
  File "<string>", line 1, in ?
  File "C:\Dokumente und Einstellungen\Administrator\Desktop\py\createBusiness_Process.py", line 22
	def createBusiness_Process(name , description , BusinessProcessPerformedByBusinessRoleListOfInsName , SupportingApplicationFunctionsListOfInsName , DeletesInformationListOfInsName , CreatesInformationListOfInsName , SupportingApplication(Groups)ListOfInsName , ReadsInformationListOfInsName , StandardisationLevelInsName , UpdatesInformationListOfInsName , LifecycleStatusInsName , BusinessProcessOwnedByBusinessRoleListOfInsName , SupportingApplicationServicesListOfInsName , ImplementedByPhysicalBusinessProcessesListOfInsName , RealisesBusinessCapabilityInsName , BusinessProcessSupplierInsName , DefiningBusinessProcessFlowInsName ):
	                                                                                                                                                                                                                                             ^
SyntaxError: invalid syntax
exception from Jython: Traceback (innermost last):
  File "<string>", line 1, in ?
  File "C:\Dokumente und Einstellungen\Administrator\Desktop\py\createBusiness_Process.py", line 22
	def createBusiness_Process(name , description , BusinessProcessPerformedByBusinessRoleListOfInsName , SupportingApplicationFunctionsListOfInsName , DeletesInformationListOfInsName , CreatesInformationListOfInsName , SupportingApplication(Groups)ListOfInsName , ReadsInformationListOfInsName , StandardisationLevelInsName , UpdatesInformationListOfInsName , LifecycleStatusInsName , BusinessProcessOwnedByBusinessRoleListOfInsName , SupportingApplicationServicesListOfInsName , ImplementedByPhysicalBusinessProcessesListOfInsName , RealisesBusinessCapabilityInsName , BusinessProcessSupplierInsName , DefiningBusinessProcessFlowInsName ):
	                                                                                                                                                                                                                                             ^
SyntaxError: invalid syntax
: Traceback (innermost last):
  File "<string>", line 1, in ?
  File "C:\Dokumente und Einstellungen\Administrator\Desktop\py\createBusiness_Process.py", line 22
	def createBusiness_Process(name , description , BusinessProcessPerformedByBusinessRoleListOfInsName , SupportingApplicationFunctionsListOfInsName , DeletesInformationListOfInsName , CreatesInformationListOfInsName , SupportingApplication(Groups)ListOfInsName , ReadsInformationListOfInsName , StandardisationLevelInsName , UpdatesInformationListOfInsName , LifecycleStatusInsName , BusinessProcessOwnedByBusinessRoleListOfInsName , SupportingApplicationServicesListOfInsName , ImplementedByPhysicalBusinessProcessesListOfInsName , RealisesBusinessCapabilityInsName , BusinessProcessSupplierInsName , DefiningBusinessProcessFlowInsName ):
	                                                                                                                                                                                                                                             ^
SyntaxError: invalid syntax
I don't really know whats wrong with the syntax, because I copied the text after generate("Business_Process") in a py file but when loading I get an syntax error, as you can see.
Because of the fact that I am not an expert in python I would be happy if someone could help me with that problem.

I already did the same with generate("Application") und it worked. I finally could add some applications by using the excel sheet.
User avatar
jonathan.carter
Posts: 1087
Joined: 04 Feb 2009, 15:44

Many of the parameters that you're passing into that createBusiness_Process() function are actually references to other instances in the repository, e.g. the Business Roles.

If those parameters have not been initialised correctly (e.g. by finding or creating a reference to the required Role) then Python may assume that they are Strings and cause the syntax error because underneath, in the Protege API, an 'Instance' object is expected.
Essential Project Team
Post Reply