|
Algernon Software | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.algernon.app.AlgernonApplication org.algernon.app.Java2Protege
Java2Protege converts a Java package to a Protege ontology. Input is a Java package name and the filename of a Protege project (.pprj file). The package must be on the classpath. If the Protege project exists, the classes are added to it. If it doesn't, a new knowledge base is created and saved to the given file. Þ The program first builds an ontology, then creates template slots on each class corresponding to all the get...() methods on each class. Enumerations are converted to Strings due to probably name conflicts. Any class starting or ending with 'Enum' or 'Enumeration' is assumed to be an enumeration.
Field Summary | |
(package private) static String |
CHILD_ERROR_STRING
|
(package private) static String |
DEFAULT_ROOT_CLASS
|
(package private) String |
f_adviceFile
|
(package private) AdviceTable |
f_adviceTable
|
(package private) static String[] |
f_adviceTableColumnNames
|
(package private) Algernon |
f_algy
|
(package private) FrameTree |
f_classTable
|
(package private) SimpleTree |
f_classTree
|
(package private) String |
f_errors
|
(package private) boolean |
f_ignoreEnumerations
|
(package private) AlgernonKB |
f_kb
|
(package private) String |
f_kbFile
|
(package private) String |
f_outputFile
|
(package private) String |
f_package
|
(package private) String |
f_saveInAlgernonFile
|
(package private) SlotTable |
f_slotTable
|
(package private) static String[] |
f_slotTableColumnNames
|
(package private) String |
f_topRoot
|
(package private) J2PWindow |
f_window
|
static String |
HELP_URL
|
Fields inherited from class org.algernon.app.AlgernonApplication |
|
Constructor Summary | |
Java2Protege()
|
Method Summary | |
void |
addAdvice(String command,
String type,
String frameName,
String replacement)
Processes and stores the advice. |
private void |
checkForDuplicateFrames(String s)
Adds an error to classes if they have the same name as the given slot. |
private void |
checkSlotDomainAndRange(J2PSlot slot)
|
private String |
classesToAlgernon(FrameTree classTable,
String topRoot)
Creates Algernon taxonomy from stored information about class structure. |
String |
convertRelationRange(Class rangeType,
String relation,
Class domain)
Converts a Java type to a Protege type. |
int |
countNameUses(String name)
Returns the number of times the name is used. |
AdviceTable |
createAdviceTable()
|
private void |
createClassDataStructures(SimpleTree classTree)
Creates the data structures for storing potential classes. |
private void |
createClassDataStructuresAux(Class aClass,
J2PClass superClass,
SimpleTree classTree)
Recursive method to create class and subclass data structures. |
private void |
createSlotDataStructures(SimpleTree classTree)
Creates the data structures for storing potential slots. |
private void |
createSlotDataStructuresAux(Class domainClass)
Helper method for createSlotDataStructures. |
SlotTable |
createSlotTable()
|
void |
deleteAdvice(Vector values)
See documentation below. |
void |
doCheckErrors(FrameTree f_classTable,
SlotTable slotTable)
Checks for errors (usually duplicate names) and stores errors on each frame. |
boolean |
doConversion(String packageName,
String projectFile,
String rootClass,
String adviceFile)
Performs the conversion. |
void |
doWriteAdviceFile(String filename)
Writes the contents of the advice to a file. |
String |
doWriteAlgernonFile(String outFilename,
String rootClass)
Writes everything to an Algernon file. |
Advice |
getAdvice()
|
Vector |
getAdviceColumnNames()
|
String |
getAdviceFile()
|
private String |
getAlgernonMetaTaxonomy()
|
String |
getClassMappingInfo(J2PFrame aClass,
FrameTree classTree)
Returns a TELL statement that creates a mapping frame that stores the mapping between a Java name (Class or field) and a Protege Class. |
FrameTree |
getClassTable()
|
String |
getKBFile()
|
String |
getKBRoot()
|
private String |
getMappingInfo(FrameTree classTable,
SlotTable slotTable)
Returns the mapping info to convert from Protege names to Java names. |
String |
getPackage()
|
String |
getSaveInAlgernonFile()
Returns the name of the file in which to save Algernon files. |
String |
getSlotMappingInfo(J2PSlot slot)
Returns a TELL statement that creates a mapping frame that stores the mapping between a Java name (Class or field) and a Protege Slot. |
SlotTable |
getSlotTable()
|
String |
getToolTipText(String className)
|
void |
init(String[] args)
Initializes variables from the command-line arguments. |
boolean |
isBuiltinRange(String range)
returns true if the string represents an atomic slot range such as :INTEGER. |
private boolean |
isEnumeration(String name)
|
boolean |
isValidPackage(String packageName)
|
static void |
main(String[] args)
java org.algernon.app.Java2Protege package Protege-project-file advice-file |
static String |
mappingOfSlot(J2PSlot slot)
Returns the name of the mapping object in the KB that corresponds to this slot. |
static String |
mappingOfSlot(String className,
String slotName)
Returns the name of the mapping object in the KB that corresponds to this slot. |
void |
newKB(String name)
Creates a new KB for the system to use. |
void |
run()
Performs the operations. |
void |
saveKB()
Saves the kb. |
private void |
setDuplicateSlotNameErrorOnClasses(J2PSlot slot)
Adds an error to classes if they have the same name as the given slot. |
void |
setKB(String projectFile)
Sets the KB used with this program. |
void |
showMessage(String message,
String title,
int messageType)
Displays an error message, using the GUI if possible. |
private String |
singularForm(String word)
|
private String |
slotsToAlgernon(SlotTable slotTable)
Returns a set of TELL statements that use :ADD-RELATION to create new slots. |
private String |
slotToAlgernonSlot(J2PSlot slot)
|
private String |
treeBranchToTaxonomy(J2PFrame aClass,
FrameTree classTree,
String indent)
|
Methods inherited from class org.algernon.app.AlgernonApplication |
getName, getVersionDate, getVersionMajor, getVersionMicro, getVersionMinor, getVersionString, getVersionType, getVersionURL |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String HELP_URL
static String CHILD_ERROR_STRING
static String[] f_slotTableColumnNames
static String[] f_adviceTableColumnNames
static String DEFAULT_ROOT_CLASS
boolean f_ignoreEnumerations
String f_package
String f_kbFile
String f_adviceFile
String f_outputFile
String f_saveInAlgernonFile
String f_topRoot
FrameTree f_classTable
SlotTable f_slotTable
AdviceTable f_adviceTable
AlgernonKB f_kb
J2PWindow f_window
SimpleTree f_classTree
String f_errors
Algernon f_algy
Constructor Detail |
public Java2Protege()
Method Detail |
public void init(String[] args)
args
- (in order) package, Protege project file, advice filepublic static void main(String[] args)
args
- public void run()
run
in interface Runnable
public String doWriteAlgernonFile(String outFilename, String rootClass)
private String getMappingInfo(FrameTree classTable, SlotTable slotTable)
classTable
- slotTable
-
public String getClassMappingInfo(J2PFrame aClass, FrameTree classTree)
public static String mappingOfSlot(J2PSlot slot)
slot
- The slot to be used to create the mapping name.
public static String mappingOfSlot(String className, String slotName)
className
- the name of the class that has the slot.slotName
- the name of the slot to be used to create the mapping name.
public String getSlotMappingInfo(J2PSlot slot)
private String getAlgernonMetaTaxonomy()
public void setKB(String projectFile) throws AlgernonStorageException
AlgernonStorageException
public void newKB(String name)
public void saveKB() throws AlgernonStorageException
AlgernonStorageException
private void createClassDataStructures(SimpleTree classTree)
classTree
- private void createClassDataStructuresAux(Class aClass, J2PClass superClass, SimpleTree classTree)
aClass
- Class to start with (root of subtree)superClass
- Superclass of aClassclassTree
- Contains the tree mapping.private void createSlotDataStructures(SimpleTree classTree)
classTree
- private void createSlotDataStructuresAux(Class domainClass)
private String slotsToAlgernon(SlotTable slotTable)
private String slotToAlgernonSlot(J2PSlot slot)
public String convertRelationRange(Class rangeType, String relation, Class domain)
1. If the range is a collection class, returns the singular form of the relation name. I.e. Records returns Record. 2. long, short, int, integer become :INTEGER 3. float, double become :DOUBLE 4. boolean becomes :BOOLEAN 5. string becomes :STRING 6. EnumXyz or EnumerationXyz or XyzEnum or XyzEnumeration become :STRING. 7. Date becomes :STRING
rangeType
- the Class of the method's return type.relation
- the name of the relation being worked on
private boolean isEnumeration(String name)
private String singularForm(String word)
private String classesToAlgernon(FrameTree classTable, String topRoot)
classTable
- stored informationtopRoot
- Frame name to use as the root of the Taxonomy.private String treeBranchToTaxonomy(J2PFrame aClass, FrameTree classTree, String indent)
public boolean isBuiltinRange(String range)
public boolean isValidPackage(String packageName)
public boolean doConversion(String packageName, String projectFile, String rootClass, String adviceFile) throws J2PConversionError
packageName
- projectFile
- adviceFile
-
J2PConversionError
public void doCheckErrors(FrameTree f_classTable, SlotTable slotTable)
private void checkForDuplicateFrames(String s)
s
- the name of a class.public int countNameUses(String name)
name
- the name to checkprivate void checkSlotDomainAndRange(J2PSlot slot)
private void setDuplicateSlotNameErrorOnClasses(J2PSlot slot)
slot
- the slot to check against the frames.public String getPackage()
public String getKBFile()
public String getAdviceFile()
public FrameTree getClassTable()
public SlotTable getSlotTable()
public String getToolTipText(String className)
public SlotTable createSlotTable()
public AdviceTable createAdviceTable()
public Advice getAdvice()
public Vector getAdviceColumnNames()
public String getSaveInAlgernonFile()
public void showMessage(String message, String title, int messageType)
message
- The message to be displayedmessageType
- JOptionPane.WARNING_MESSAGE, etc.public void doWriteAdviceFile(String filename) throws IOException
filename
- the name of the file to save to.
IOException
public void addAdvice(String command, String type, String frameName, String replacement)
type
- Must be SLOT or CLASS, but is not case-sensitive.frameName
- Either ALL (uppercase) or the name of a frame (case-sensitive).command
- Not case-sensitive. Must be PREFIX, SUFFIX, CAPITALIZE, LOWERCASE, UPPERCASE or REPLACEreplacement
- Case-sensitive. The new name for the slot or class, in a REPLACE command.public void deleteAdvice(Vector values)
Command: IGNORE, CAPITALIZE, etc. Type: CLASS or SLOT frameName: a frame name replacement: a string or nullAll items are strings or are null.
values
- A Vector of strings.public String getKBRoot()
|
Algernon Software | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |