Adding Enumerations

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

Hi all,

I've been trying to add a new Enumeration, let's call it Heatmap_Status, so I add it manually, from Class Browser I click on the Create Class button and update the name of it, and start adding Instances for this class.

But when I try to add Instances with a function:

createTechnology.py
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, heatmapStatus, heatmapTechnology):
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)
theHeatmap = getEssentialInstanceContains("Heatmap_status",heatmapStatus + "_" + date, "External Essential Repository", heatmapStatus)
setSlot(theProductRole,"strategic_heatmap_status",theHeatmap)
theFunction = getEssentialInstanceContains("Technology_Function",heatmapTechnology + "_" + date, "External Essential Repository", heatmapTechnology)
setSlot(theProduct, "technology_product_functions_offered", theFunction)
setSlot(theRole, "technology_component_functions_offered", theFunction)
An error pops up:
Welcome to the Protégé shell
>>> execfile("C:/EssentialAM/RepositoryIntegration/standardFunctions.txt")
>>> execfile("C:/EssentialAM/Python/createTechnology.py")
>>> createTechnology("Windows","Microsoft Windows is a Desktop Operating System","XP","Microsoft","Desktop Operating System","Production","Preferred","Platforms")
Updated instance: Microsoft_160211123115151, Essential name: Microsoft
Updated instance: Windows_XP_160211123115151, Essential name: Windows XP
Created new instance: Microsoft_Windows_Desktop Operating System_160211123115151, Essential name: Microsoft::Windows::as::Desktop Operating System
Updated instance: Desktop Operating System_160211123115151, Essential name: Desktop Operating System
Updated instance: Production_160211123115151, Essential name: Production
Traceback (innermost last):
File "<string>", line 1, in ?
File "C:/EssentialAM/Python/createTechnology.py", line 25, in createTechnology
File "C:/EssentialAM/RepositoryIntegration/standardFunctions.txt", line 159, in getEssentialInstanceContains
AttributeError: 'NoneType' object has no attribute 'getDirectInstances'
exception from Jython: Traceback (innermost last):
File "<string>", line 1, in ?
File "C:/EssentialAM/Python/createTechnology.py", line 25, in createTechnology
File "C:/EssentialAM/RepositoryIntegration/standardFunctions.txt", line 159, in getEssentialInstanceContains
AttributeError: 'NoneType' object has no attribute 'getDirectInstances'
: Traceback (innermost last):
File "<string>", line 1, in ?
File "C:/EssentialAM/Python/createTechnology.py", line 25, in createTechnology
File "C:/EssentialAM/RepositoryIntegration/standardFunctions.txt", line 159, in getEssentialInstanceContains
AttributeError: 'NoneType' object has no attribute 'getDirectInstances'

>>>
What does "AttributeError: 'NoneType' object has no attribute 'getDirectInstances'" means??

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

What this tends to mean is that you've tried to get a set of instances from a class that does not exist - or even when the call has been made down the stack of function calls, there's actually no class name specified.

I think it might be associated with the getEssentialInstanceContains() call to the Heatmap_status. Have you already defined the Class for that? If not, I think this might be the problem.

The integration functions are designed to create Instances only. We use a different suite of functions as part of our meta model update scripts to add and modify the Classes. If you have not already defined the Heatmap_status class, create a new class as a subclass of Enumeration. It will only take a moment to do by hand.

Hope this solves it - let me know how you get on

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

Hi Jonathan,

Yeap, I've already added a subclass from Enumeration called Heatmap_Status and also added manually some instances (Emerging, Preferred, Declining, Eliminate and Deprecated), saved the project and restarted the protege...

Image

So, at this point I already have the class created with some instances in it, I'll use the standardfunction.txt to get an instance I've already created:
Welcome to the Protégé shell
>>> execfile("C:/EssentialAM/RepositoryIntegration/standardFunctions.txt")
>>> execfile("C:/EssentialAM/Python/createTechnology.py")
>>> theHeatmap = getEssentialInstanceContains("Heatmap_status", "Emerging", "External Essential Repository", "Emerging")
Traceback (innermost last):
File "<string>", line 1, in ?
File "C:/EssentialAM/RepositoryIntegration/standardFunctions.txt", line 159, in getEssentialInstanceContains
AttributeError: 'NoneType' object has no attribute 'getDirectInstances'
exception from Jython: Traceback (innermost last):
File "<string>", line 1, in ?
File "C:/EssentialAM/RepositoryIntegration/standardFunctions.txt", line 159, in getEssentialInstanceContains
AttributeError: 'NoneType' object has no attribute 'getDirectInstances'
: Traceback (innermost last):
File "<string>", line 1, in ?
File "C:/EssentialAM/RepositoryIntegration/standardFunctions.txt", line 159, in getEssentialInstanceContains
AttributeError: 'NoneType' object has no attribute 'getDirectInstances'
>>>
And also double checked at the Instance Tree, on :SYSTEM-CLASS > :META-CLASS > :CLASS > :STANDARD-CLASS, if Heatmap_Status exists, and it does...

Image

Any thoughts??

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

I think it's a simple typo in your import code.
The call to getEssentialInstanceNN() uses 'Heatmap_status', whereas the class name is 'Heatmap_Status' in Protege. Finding the correct class is case sensitive.

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

OMFG!!! You're riiiiite!! Hahahahahaha!! I've already start debbugging the function and stuff!!... yeah well, things like this happen rite?? :)

Thank you so much :)

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

Absolutely!

One thing that you might want to have a look at is the Script Console tab in Protege. I often use this while I'm testing out what my script needs to do. It's very useful for seeing what the functions (both the standardFunctions or the Protege API) will give you - and it helps iron out little slips like this!

Jonathan
Essential Project Team
Post Reply