initial commit
This commit is contained in:
commit
9e2950ab33
11 changed files with 1047 additions and 0 deletions
19
META-INF/MANIFEST.MF
Normal file
19
META-INF/MANIFEST.MF
Normal file
|
@ -0,0 +1,19 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Hets
|
||||
Bundle-SymbolicName: de.unibremen.informatik.hets;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: de.unibremen.informatik.hets.protege.Activator
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Import-Package: org.osgi.framework;version="1.3.0",
|
||||
org.protege.owlapi.apibinding,
|
||||
org.protege.owlapi.model,
|
||||
org.semanticweb.owlapi.model,
|
||||
javax.swing
|
||||
Require-Bundle: org.eclipse.equinox.registry,
|
||||
org.eclipse.equinox.common,
|
||||
org.protege.common;bundle-version="4.1.0",
|
||||
org.protege.editor.core.application;bundle-version="4.1.0",
|
||||
org.protege.editor.owl;bundle-version="4.1.0",
|
||||
org.semanticweb.owl.owlapi;bundle-version="3.0.0"
|
267
build.xml
Normal file
267
build.xml
Normal file
|
@ -0,0 +1,267 @@
|
|||
<?xml version = "1.0" encoding = "utf-8"?>
|
||||
<project name = "sample plugin project" default = "install" basedir = ".">
|
||||
|
||||
<!--
|
||||
To run this build file set the environment variable
|
||||
PROTEGE_HOME to point to a protege distribution and type ant
|
||||
install or jar.
|
||||
-->
|
||||
|
||||
<property environment="env"/>
|
||||
<property name = "protege.home" location="${env.PROTEGE_HOME}"/>
|
||||
|
||||
<property file = "${protege.home}/build.properties"/>
|
||||
|
||||
<property file="local.properties"/>
|
||||
|
||||
|
||||
<!--
|
||||
**** CHANGE ME ****
|
||||
|
||||
This setting defines the name of the plugin.
|
||||
This may be the only setting that the developer needs to
|
||||
change.
|
||||
-->
|
||||
<property name = "plugin" value = "de.unibremen.informatik.hets"/>
|
||||
|
||||
<!--
|
||||
these properties probably don't need changing
|
||||
-->
|
||||
<property name = "src" location = "./src"/>
|
||||
<property name = "build" location = "./build"/>
|
||||
<property name = "bundle.dir" location = "${build}"/>
|
||||
<property name = "classes" location = "${build}/classes"/>
|
||||
<property name = "lib" location = "./lib"/>
|
||||
<property name = "genlib" location = "${build}/lib"/>
|
||||
<property name = "manifest" location = "${build}/manifest.mf"/>
|
||||
|
||||
<property name = "protege.common" location="${protege.home}/bundles"/>
|
||||
<property name = "protege.plugins" location="${protege.home}/plugins"/>
|
||||
|
||||
|
||||
<target name = "init">
|
||||
<tstamp>
|
||||
<format property="build.time" pattern="MM/dd/yyyy hh:mm aa"/>
|
||||
</tstamp>
|
||||
<mkdir dir = "${build}"/>
|
||||
<mkdir dir = "${classes}"/>
|
||||
<!-- <mkdir dir = "${classes}/lib"/> -->
|
||||
<mkdir dir = "${genlib}"/>
|
||||
</target>
|
||||
|
||||
<!-- ============================================================= -->
|
||||
<!-- Configuring the Compile Classpath -->
|
||||
<!-- ============================================================= -->
|
||||
|
||||
|
||||
<target name="checkProtegeLibsAndReport" depends="checkProtegeLibs"
|
||||
unless="libs.found">
|
||||
<echo message="Missing protege libraries. You need to set "/>
|
||||
<echo message="the PROTEGE_HOME environment variable to a"/>
|
||||
<echo message="protege installation directory where the"/>
|
||||
<echo message="appropriate plugins have been installed."/>
|
||||
<echo message="Alternatively set the jar libs in local.properties (protege.lib=...)"/>
|
||||
<echo message="Use the -v option to ant to see what jars are missing."/>
|
||||
<fail message = "missing protege libraries"/>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
**** CHANGE ME ****
|
||||
|
||||
The following target only needs to be modified if the user
|
||||
needs to change the classpath. It is preconfigured to use
|
||||
the common protege 4 jars, the lib directory and the
|
||||
libraries that have been uncovered in buildlibs.
|
||||
-->
|
||||
<target name = "checkProtegeLibs" depends="init">
|
||||
<echo message="Using Protege Home = ${protege.home} to find protege jars"/>
|
||||
<condition property="libs.found">
|
||||
<and>
|
||||
<available file="${protege.osgi}" type="file"/>
|
||||
<available file="${equinox.common}" type = "file"/>
|
||||
<available file="${equinox.registry}" type = "file"/>
|
||||
<!-- <available file="${owl.editor.jar}" type = "file"/> -->
|
||||
<available file="${owl.lib}" type="file"/>
|
||||
</and>
|
||||
</condition>
|
||||
<path id = "project.classpath">
|
||||
<pathelement location="${protege.osgi}"/>
|
||||
<pathelement location="${protege.lib}"/>
|
||||
<pathelement location="${equinox.common}"/>
|
||||
<pathelement location="${equinox.registry}"/>
|
||||
<pathelement location="${owl.editor.jar}"/>
|
||||
<pathelement location="${owl.lib}"/>
|
||||
<!-- <fileset dir="${lib}"/> -->
|
||||
<fileset dir="${genlib}"/>
|
||||
</path>
|
||||
</target>
|
||||
|
||||
|
||||
<!--
|
||||
**** CHANGE ME ****
|
||||
|
||||
The following target only needs to be modified if the
|
||||
developer needs to obtain some jar files that are contained in
|
||||
the Protege bundles. The contents of these jar files are
|
||||
found when Protege 4 runs but may be needed in order to
|
||||
compile the plugin.
|
||||
-->
|
||||
<target name = "buildlibs" depends="checkProtegeLibsAndReport">
|
||||
<unjar dest="${build}"
|
||||
src="${common.lib}">
|
||||
<patternset>
|
||||
<include name = "**/log4j.jar"/>
|
||||
<include name = "**/looks.jar"/>
|
||||
</patternset>
|
||||
</unjar>
|
||||
</target>
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
**** CHANGE ME ****
|
||||
|
||||
Here is the copy.resources target. It may need modification
|
||||
to copy the right resources into the classes directory. By
|
||||
default it already copies non-java files found in the source
|
||||
directory, the libraries needed by the project and the
|
||||
viewconfig and the plugin.xml. This will be sufficient in
|
||||
many cases.
|
||||
-->
|
||||
<target name="copy.resources" depends="build.manifest">
|
||||
<copy todir="${classes}">
|
||||
<fileset dir="${src}">
|
||||
<include name="**/*"/>
|
||||
<exclude name="**/*.java"/>
|
||||
<exclude name="**/MANIFEST.MF"/>
|
||||
<exclude name="**/manifest.mf"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<!-- <copy todir="${classes}/lib">
|
||||
<fileset dir="${lib}" excludes="junit*.jar"/>
|
||||
</copy> -->
|
||||
<copy todir="${classes}">
|
||||
<fileset dir="." includes="*.xml">
|
||||
<exclude name="build.xml"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<!-- the manifest doesn't belong here but this is good for IDE's -->
|
||||
<mkdir dir="${classes}/META-INF"/>
|
||||
<copy todir="${classes}/META-INF"
|
||||
file = "${manifest}"/>
|
||||
</target>
|
||||
|
||||
|
||||
<!--
|
||||
It is less likely that the developer will want to make changes
|
||||
below this line
|
||||
-->
|
||||
<!-- ============================================================= -->
|
||||
|
||||
<target name = "jjtree">
|
||||
<jjtree target="./src/de/unibremen/informatik/hets/grammar/HetCASLGrammar.jjt"
|
||||
outputdirectory="./src/de/unibremen/informatik/hets/grammar/"
|
||||
javacchome="/usr/share/java/"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name = "javacc" depends = "jjtree">
|
||||
<javacc target="./src/de/unibremen/informatik/hets/grammar/HetCASLGrammar.jj"
|
||||
outputdirectory="./src/de/unibremen/informatik/hets/grammar/"
|
||||
javacchome="/usr/share/java/"
|
||||
/>
|
||||
</target>
|
||||
|
||||
<target name = "compile" depends = "buildlibs, checkProtegeLibsAndReport, javacc">
|
||||
<javac srcdir = "${src}"
|
||||
destdir = "${classes}"
|
||||
debug="on"
|
||||
includeAntRuntime="false">
|
||||
<classpath refid = "project.classpath"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="build.manifest">
|
||||
<copy tofile="${manifest}"
|
||||
file="META-INF/MANIFEST.MF" overwrite="true"/>
|
||||
<manifest file="${manifest}"
|
||||
mode = "update">
|
||||
<attribute name="Built-By" value = "${user.name}"/>
|
||||
<attribute name="Build-Date" value = "${build.time}"/>
|
||||
</manifest>
|
||||
</target>
|
||||
|
||||
<target name = "jar" depends = "compile, copy.resources">
|
||||
<jar jarfile = "${build}/${plugin}.jar"
|
||||
basedir = "${classes}"
|
||||
manifest = "${build}/manifest.mf"/>
|
||||
</target>
|
||||
|
||||
<target name = "install" depends = "jar">
|
||||
<!-- flush cache -->
|
||||
<delete dir = "${protege.home}/configuration/org.eclipse.core.runtime"/>
|
||||
<delete dir = "${protege.home}/configuration/org.eclipse.osgi"/>
|
||||
<copy file="${build}/${plugin}.jar"
|
||||
todir = "${protege.plugins}"
|
||||
overwrite = "true"/>
|
||||
</target>
|
||||
|
||||
<target name = "run" depends="install">
|
||||
<java fork = "true"
|
||||
dir = "${protege.home}"
|
||||
jar = "${protege.osgi}">
|
||||
<jvmarg value = "-Dfile.encoding=UTF-8"/>
|
||||
<jvmarg value = "-Xmx500M"/>
|
||||
<jvmarg value = "-Dlog4j.configuration=file:log4j.xml"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name = "debug" depends="install">
|
||||
<java fork = "true"
|
||||
dir = "${protege.home}"
|
||||
jar = "${protege.osgi}">
|
||||
<jvmarg value = "-Xmx500M"/>
|
||||
<jvmarg value = "-Dlog4j.configuration=file:log4j.xml"/>
|
||||
<jvmarg value = "-Dfile.encoding=UTF-8"/>
|
||||
<jvmarg value = "-Xrunjdwp:transport=dt_socket,address=8500,server=y,suspend=y"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<target name = "clean">
|
||||
<delete dir = "${build}"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name = "usage">
|
||||
<echo message = "To run this script set the PROTEGE_HOME environment"/>
|
||||
<echo message = "variable and use one of the following targets"/>
|
||||
<echo message = "jar - builds the jar (bundle) file for this project"/>
|
||||
<echo message = "install - installs the bundle into the Protege distribution"/>
|
||||
<echo message = "copy.resources - copyies resources into the classes directory"/>
|
||||
<echo message = " this can be useful for ide developers - see the wiki"/>
|
||||
<echo message = "run - install the plugin and run protege"/>
|
||||
<echo message = "debug - install the plugin and start protege for debug"/>
|
||||
</target>
|
||||
|
||||
|
||||
<!--
|
||||
Standard properties that should not require changing
|
||||
-->
|
||||
<property name="equinox.common"
|
||||
location="${protege.common}/org.eclipse.equinox.common.jar"/>
|
||||
<property name="equinox.registry"
|
||||
location="${protege.common}/org.eclipse.equinox.registry.jar"/>
|
||||
<property name="protege.lib"
|
||||
location="${protege.common}/org.protege.editor.core.application.jar"/>
|
||||
<property name="common.lib"
|
||||
location="${protege.common}/org.protege.common.jar"/>
|
||||
|
||||
<property name="owl.lib"
|
||||
location="${protege.plugins}/org.semanticweb.owl.owlapi.jar"/>
|
||||
|
||||
<property name="owl.editor.jar"
|
||||
location="${protege.plugins}/org.protege.editor.owl.jar"/>
|
||||
|
||||
|
||||
|
||||
</project>
|
57
plugin.xml
Normal file
57
plugin.xml
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?xml version="1.0" ?>
|
||||
<plugin>
|
||||
<extension
|
||||
id="HetsImportAction"
|
||||
point="org.protege.editor.core.application.EditorKitMenuAction">
|
||||
<name
|
||||
value="Import HetCASL">
|
||||
</name>
|
||||
<path
|
||||
value="org.protege.editor.owl.menu.tools/SlotH-A">
|
||||
</path>
|
||||
<editorKitId
|
||||
value="OWLEditorKit">
|
||||
</editorKitId>
|
||||
<class
|
||||
value="de.unibremen.informatik.hets.protege.ImportHetsAction">
|
||||
</class>
|
||||
<toolTip
|
||||
value="import OWL from HetCASL files">
|
||||
</toolTip>
|
||||
</extension>
|
||||
<extension
|
||||
id="HetsExportAction"
|
||||
point="org.protege.editor.core.application.EditorKitMenuAction">
|
||||
<name
|
||||
value="Export HetCASL">
|
||||
</name>
|
||||
<path
|
||||
value="org.protege.editor.owl.menu.tools/SlotH-B">
|
||||
</path>
|
||||
<editorKitId
|
||||
value="OWLEditorKit">
|
||||
</editorKitId>
|
||||
<class
|
||||
value="de.unibremen.informatik.hets.protege.ExportHetsAction">
|
||||
</class>
|
||||
<toolTip
|
||||
value="export OWL to HetCASL file">
|
||||
</toolTip>
|
||||
</extension>
|
||||
<extension
|
||||
id="HetCASL"
|
||||
point="org.protege.editor.core.application.ViewComponent">
|
||||
<label
|
||||
value="HetCASL rendering">
|
||||
</label>
|
||||
<class
|
||||
value="de.unibremen.informatik.hets.protege.HetCASLRenderingViewComponent">
|
||||
</class>
|
||||
<headerColor
|
||||
value="@org.protege.ontologycolor">
|
||||
</headerColor>
|
||||
<category
|
||||
value="@org.protege.ontologycategory">
|
||||
</category>
|
||||
</extension>
|
||||
</plugin>
|
270
src/de/unibremen/informatik/hets/grammar/HetCASLGrammar.jjt
Normal file
270
src/de/unibremen/informatik/hets/grammar/HetCASLGrammar.jjt
Normal file
|
@ -0,0 +1,270 @@
|
|||
options {
|
||||
// MULTI=true;
|
||||
// NODE_EXTENDS="MyNode";
|
||||
TRACK_TOKENS=true;
|
||||
UNICODE_INPUT=true;
|
||||
STATIC=false;
|
||||
}
|
||||
|
||||
PARSER_BEGIN(HetCASLParser)
|
||||
package de.unibremen.informatik.hets.grammar;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class HetCASLParser {}
|
||||
PARSER_END(HetCASLParser)
|
||||
|
||||
SKIP : { " " | "\t" | "\n" | "\r" }
|
||||
|
||||
/* COMMENTS */
|
||||
|
||||
SPECIAL_TOKEN :
|
||||
{
|
||||
<SINGLE_LINE_COMMENT: "%%" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
/* reserved */
|
||||
< _AND: "and" >
|
||||
| < _ARCH: "arch" >
|
||||
| < _AS: "as" >
|
||||
| < _AXIOM: "axiom" >
|
||||
| < _AXIOMS: "axioms" >
|
||||
| < _CLOSED: "closed" >
|
||||
| < _DEF: "def" >
|
||||
| < _ELSE: "else" >
|
||||
| < _END: "end" >
|
||||
| < _EXISTS: "exists" >
|
||||
| < _FALSE: "false" >
|
||||
| < _FIT: "fit" >
|
||||
| < _FORALL: "forall" >
|
||||
| < _FREE: "free" >
|
||||
| < _FROM: "from" >
|
||||
| < _GENERATED: "generated" >
|
||||
| < _GET: "get" >
|
||||
| < _GIVEN: "given" >
|
||||
| < _HIDE: "hide" >
|
||||
| < _IF: "if" >
|
||||
| < _IN: "in" >
|
||||
| < _LAMBDA: "lambda" >
|
||||
| < _LIBRARY: "library" >
|
||||
| < _LOCAL: "local" >
|
||||
| < _NOT: "not" >
|
||||
| < _OP: "op" >
|
||||
| < _OPS: "ops" >
|
||||
| < _PRED: "pred" >
|
||||
| < _PREDS: "preds" >
|
||||
| < _RESULT: "result" >
|
||||
| < _REVEAL: "reveal" >
|
||||
| < _SORT: "sort" >
|
||||
| < _SORTS: "sorts" >
|
||||
| < _SPEC: "spec" >
|
||||
| < _THEN: "then" >
|
||||
| < _TO: "to" >
|
||||
| < _TRUE: "true" >
|
||||
| < _TYPE: "type" >
|
||||
| < _TYPEs: "types" >
|
||||
| < _UNIT: "unit" >
|
||||
| < _UNITS: "units" >
|
||||
| < _VAR: "var" >
|
||||
| < _VARS: "vars" >
|
||||
| < _VERSION: "version" >
|
||||
| < _VIEW: "view" >
|
||||
| < _WHEN: "when" >
|
||||
| < _WITH: "with" >
|
||||
| < _WITHIN: "within" >
|
||||
/* not reserved */
|
||||
| < _ASSOC: "assoc" >
|
||||
| < _COMM: "comm" >
|
||||
| < _IDEM: "idem" >
|
||||
/* hetcasl */
|
||||
| < _LOGIC: "logic" >
|
||||
| < _DATA: "data" >
|
||||
/* helper */
|
||||
//| < _EQUALS: "=" >
|
||||
}
|
||||
|
||||
/* specification libraries */
|
||||
TOKEN : {
|
||||
< LIB_NAME : <LIB_ID> | ( <LIB_ID> <VERSION_NUMBER> ) >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< LIB_ID : <URL> | <PATH> >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< VERSION_NUMBER : ( <NUMBER> )+ >
|
||||
}
|
||||
|
||||
/* words */
|
||||
|
||||
TOKEN : {
|
||||
< WORDS : <WORD> ( "_" <WORD> )* >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< DOT_WORDS : "." <WORDS> >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< WORD : ( <WORD_CHAR> )+ >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< WORD_CHAR : <LETTER> | "’" | <DIGIT> >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< LETTER : [ "A"-"Z", "a"-"z", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É",
|
||||
"Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö",
|
||||
"Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä",
|
||||
"å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ",
|
||||
"ò", "ó", "ô", "õ", "ö", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ" ] >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< DIGIT : [ "0"-"9" ] >
|
||||
}
|
||||
|
||||
/* signs */
|
||||
|
||||
TOKEN : {
|
||||
< SIGNS : ( <SIGN> )+ >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< SIGN : [ "+", "-", "*", "/", "\\", "&", /* "=",*/ "<", ">",
|
||||
"!", "?", ":", ".", "$", "@", "#", "ˆ", "˜",
|
||||
"¡", "¿", "×", "÷", "£", "c", "±", "¶", "§",
|
||||
"1", "2", "3", "·", "c", "◦", "¬", "µ", "|" ] >
|
||||
}
|
||||
|
||||
/* literal strings and numbers */
|
||||
|
||||
TOKEN : {
|
||||
< NUMBER : ( <DIGIT> )+ >
|
||||
}
|
||||
|
||||
/* urls and paths */
|
||||
|
||||
TOKEN : {
|
||||
< PATH_CHAR : [ "A"-"Z", "a"-"z", "0"-"9",
|
||||
"$", "-", "_", "@", ".", "&", "+", "!", "*",
|
||||
"\"", "’", "(", ")", ",", ":", "~" ]
|
||||
| ("%" <HEX_CHAR> <HEX_CHAR>) >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< HEX_CHAR : [ "A"-"F", "a"-"f", "0"-"9" ] >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< PATH_WORD : ( <PATH_CHAR> )+ >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< PATH : <PATH_WORD> ( "/" <PATH_WORD> )+ >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< URL : "http://" <PATH>
|
||||
| "ftp://" <PATH>
|
||||
| "file:///" <PATH> >
|
||||
}
|
||||
|
||||
TOKEN : {
|
||||
< _EQUALS : "=" > : IN_SPEC
|
||||
}
|
||||
|
||||
<IN_SPEC> MORE : {
|
||||
< ~[] >
|
||||
}
|
||||
|
||||
<IN_SPEC> SPECIAL_TOKEN : {
|
||||
< EXT_ANNO_CONS : "%cons" >
|
||||
}
|
||||
<IN_SPEC> SPECIAL_TOKEN : {
|
||||
< EXT_ANNO_MONO : "%mono" >
|
||||
}
|
||||
<IN_SPEC> SPECIAL_TOKEN : {
|
||||
< EXT_ANNO_DEF : "%def" >
|
||||
}
|
||||
<IN_SPEC> SPECIAL_TOKEN : {
|
||||
< EXT_ANNO_IMPLIES : "%implies" >
|
||||
}
|
||||
|
||||
<IN_SPEC> TOKEN : {
|
||||
// < SPEC_AND : <_AND> > : IN_SPEC
|
||||
< SPEC_THEN : <_THEN> > : IN_SPEC
|
||||
| < SPEC_END : <_END> > : DEFAULT
|
||||
}
|
||||
|
||||
/* basic spec */
|
||||
|
||||
SimpleNode LIB_DEFN() :
|
||||
{
|
||||
String value;
|
||||
Token t;
|
||||
}
|
||||
{
|
||||
<_LIBRARY> t=<LIB_NAME> ( LOGIC() )+
|
||||
{
|
||||
value = t.image;
|
||||
jjtThis.jjtSetValue(value);
|
||||
return jjtThis;
|
||||
}
|
||||
}
|
||||
|
||||
void LOGIC() :
|
||||
{
|
||||
String value;
|
||||
Token t;
|
||||
}
|
||||
{
|
||||
<_LOGIC> t=<WORDS> ( SPEC_DEFN() )+
|
||||
{
|
||||
value = t.image;
|
||||
jjtThis.jjtSetValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
void SPEC_DEFN() :
|
||||
{
|
||||
String value;
|
||||
Token t;
|
||||
}
|
||||
{
|
||||
<_SPEC> t=<WORDS> <_EQUALS> ( SPEC_END() | ( SPEC_THEN() )+ SPEC_END() )
|
||||
{
|
||||
value = t.image;
|
||||
jjtThis.jjtSetValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
void SPEC_END() :
|
||||
{
|
||||
String value;
|
||||
Token t;
|
||||
}
|
||||
{
|
||||
t = <SPEC_END>
|
||||
{
|
||||
t.image = t.image.substring(0, t.image.length()-3);
|
||||
value = t.image;
|
||||
jjtThis.jjtSetValue(value);
|
||||
}
|
||||
}
|
||||
void SPEC_THEN() :
|
||||
{
|
||||
String value;
|
||||
Token t;
|
||||
}
|
||||
{
|
||||
t = <SPEC_THEN>
|
||||
{
|
||||
t.image = t.image.substring(0, t.image.length()-4);
|
||||
value = t.image;
|
||||
jjtThis.jjtSetValue(value);
|
||||
}
|
||||
}
|
27
src/de/unibremen/informatik/hets/protege/Activator.java
Normal file
27
src/de/unibremen/informatik/hets/protege/Activator.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package de.unibremen.informatik.hets.protege;
|
||||
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
|
||||
|
||||
public class Activator implements BundleActivator {
|
||||
|
||||
//private OWLDataFactory dataFactory;
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
System.out.println("Hello Woaaaarld!!");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
System.out.println("Goodbye World!!");
|
||||
}
|
||||
|
||||
}
|
0
src/de/unibremen/informatik/hets/protege/Aterm.java
Normal file
0
src/de/unibremen/informatik/hets/protege/Aterm.java
Normal file
107
src/de/unibremen/informatik/hets/protege/ExportHetsAction.java
Normal file
107
src/de/unibremen/informatik/hets/protege/ExportHetsAction.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
package de.unibremen.informatik.hets.protege;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.protege.editor.core.ui.util.UIUtil;
|
||||
import org.protege.editor.owl.ui.action.ProtegeOWLAction;
|
||||
import org.semanticweb.owlapi.model.OWLOntologyManager;
|
||||
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
|
||||
import org.semanticweb.owlapi.io.StreamDocumentTarget;
|
||||
|
||||
import org.semanticweb.owlapi.model.OWLOntology;
|
||||
|
||||
import de.unibremen.informatik.hets.protege.ImportHetsAction;
|
||||
import org.semanticweb.owlapi.model.IRI;
|
||||
|
||||
public class ExportHetsAction extends ProtegeOWLAction {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 8507263538705345008L;
|
||||
|
||||
public ExportHetsAction() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialise() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
String dumpOntologyToString(String name) {
|
||||
String result;
|
||||
|
||||
OWLOntologyManager ontologymanager = this.getOWLModelManager().getOWLOntologyManager();
|
||||
ByteArrayOutputStream outputstream = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
ontologymanager.saveOntology(ontologymanager.getOntology(IRI.create("http://informatik.uni-bremen.de/hets/"+name+".het")), outputstream);
|
||||
} catch (OWLOntologyStorageException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
result = outputstream.toString();
|
||||
result = result.replaceAll("(?m)^Prefix: .*$", "");
|
||||
result = result.replaceAll("(?m)^Ontology: .*$", "");
|
||||
result = result.replaceAll("(?m)^Import: .*$", "");
|
||||
result = result.replaceAll("(?m)^\\s*$[\n\r]{1,}", "");
|
||||
result = result.replaceAll("(?m)(^.*$)", " $1");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
/*
|
||||
Set<String> exts = new HashSet<String>();
|
||||
exts.add("het");
|
||||
exts.add("owl");
|
||||
UIUtil.saveFile(this.getOWLWorkspace(), "title", "description", exts, "foobar.het");
|
||||
System.out.println(this.getOWLModelManager().getActiveOntology());
|
||||
this.getOWLModelManager().getOWLOntologyManager().addOntologyStorer(new HetCASLOntologyStorer());
|
||||
this.getOWLWorkspace();
|
||||
try {
|
||||
this.getOWLModelManager().getOWLOntologyManager().saveOntology(this.getOWLModelManager().getActiveOntology(), new HetCASLOntologyFormat(), new StreamDocumentTarget(System.out));
|
||||
} catch (OWLOntologyStorageException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}*/
|
||||
|
||||
|
||||
Set<String> exts = new HashSet<String>();
|
||||
exts.add("het");
|
||||
exts.add("owl");
|
||||
File f = UIUtil.saveFile(this.getOWLWorkspace(), "title", "description", exts, "foobar.het");
|
||||
if (f.exists()) {
|
||||
// TODO: ask if overwrite
|
||||
f.delete();
|
||||
}
|
||||
FileOutputStream outputFile = null;
|
||||
try {
|
||||
outputFile = new FileOutputStream(f, true);
|
||||
int i;
|
||||
for (i = 0; i < ImportHetsAction.parts.size()-1; i++) {
|
||||
outputFile.write(ImportHetsAction.parts.get(i).getBytes());
|
||||
outputFile.write(dumpOntologyToString(ImportHetsAction.owl_parts.get(i)).getBytes());
|
||||
}
|
||||
outputFile.write(ImportHetsAction.parts.get(i).getBytes());
|
||||
outputFile.close();
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package de.unibremen.informatik.hets.protege;
|
||||
|
||||
import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat;
|
||||
|
||||
public class HetCASLOntologyFormat extends ManchesterOWLSyntaxOntologyFormat {
|
||||
|
||||
public HetCASLOntologyFormat() {
|
||||
setDefaultPrefix("http://informatik.uni-bremen.de/hets#");
|
||||
}
|
||||
|
||||
public HetCASLOntologyFormat(String prefix) {
|
||||
setDefaultPrefix(prefix);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "HetCASL";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package de.unibremen.informatik.hets.protege;
|
||||
|
||||
import org.semanticweb.owlapi.model.OWLOntologyFormat;
|
||||
|
||||
import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxOntologyStorer;
|
||||
|
||||
public class HetCASLOntologyStorer extends ManchesterOWLSyntaxOntologyStorer {
|
||||
|
||||
public boolean canStoreOntology(OWLOntologyFormat arg0) {
|
||||
return arg0.equals(new HetCASLOntologyFormat());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package de.unibremen.informatik.hets.protege;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
import org.protege.editor.owl.ui.view.ontology.AbstractOntologyRenderingViewComponent;
|
||||
import org.semanticweb.owlapi.model.OWLOntology;
|
||||
|
||||
import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxRenderer;
|
||||
|
||||
public class HetCASLRenderingViewComponent extends AbstractOntologyRenderingViewComponent {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 3845613418666267771L;
|
||||
|
||||
@Override
|
||||
protected void renderOntology(OWLOntology ontology, Writer writer) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
ManchesterOWLSyntaxRenderer ren = new ManchesterOWLSyntaxRenderer(getOWLModelManager().getOWLOntologyManager());
|
||||
ren.render(ontology, writer);
|
||||
writer.flush();
|
||||
}
|
||||
}
|
246
src/de/unibremen/informatik/hets/protege/ImportHetsAction.java
Normal file
246
src/de/unibremen/informatik/hets/protege/ImportHetsAction.java
Normal file
|
@ -0,0 +1,246 @@
|
|||
package de.unibremen.informatik.hets.protege;
|
||||
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.ActionEvent;
|
||||
import org.protege.editor.core.ui.util.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import org.protege.editor.owl.ui.action.ProtegeOWLAction;
|
||||
import org.semanticweb.owlapi.apibinding.OWLManager;
|
||||
import org.semanticweb.owlapi.model.AddImport;
|
||||
import org.semanticweb.owlapi.model.IRI;
|
||||
import org.semanticweb.owlapi.model.OWLClass;
|
||||
import org.semanticweb.owlapi.model.OWLOntology;
|
||||
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
|
||||
import org.semanticweb.owlapi.model.OWLOntologyManager;
|
||||
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
|
||||
import org.semanticweb.owlapi.util.SimpleIRIMapper;
|
||||
|
||||
import de.unibremen.informatik.hets.grammar.HetCASLParser;
|
||||
import de.unibremen.informatik.hets.grammar.ParseException;
|
||||
import de.unibremen.informatik.hets.grammar.SimpleNode;
|
||||
|
||||
public class ImportHetsAction extends ProtegeOWLAction {
|
||||
|
||||
public static ArrayList<String> parts;
|
||||
public static Hashtable<String, OWLOntology> ontologies;
|
||||
public static ArrayList<String> owl_parts;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4056096587762591108L;
|
||||
|
||||
@Override
|
||||
public void initialise() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
OWLOntology loadOntologyFromString(OWLOntologyManager manager, String str, String iri) {
|
||||
OWLOntology ont;
|
||||
try {
|
||||
str = "Ontology: <http://informatik.uni-bremen.de/hets/"+iri+".het>\n"
|
||||
+ "Prefix: : <http://informatik.uni-bremen.de/hets/"+iri+".het#>\n"
|
||||
+ str;
|
||||
ont = manager.loadOntologyFromOntologyDocument(new ByteArrayInputStream(str.getBytes()));
|
||||
} catch (OWLOntologyCreationException e1) {
|
||||
System.out.println(" -- begin");
|
||||
System.out.println(str);
|
||||
System.out.println("-- end");
|
||||
e1.printStackTrace();
|
||||
ont = null;
|
||||
}
|
||||
return ont;
|
||||
}
|
||||
|
||||
void saveOntologyToStream(OWLOntologyManager manager, OWLOntology ont, OutputStream out, String defaultprefix) {
|
||||
try {
|
||||
manager.saveOntology(ont, new HetCASLOntologyFormat(defaultprefix), out);
|
||||
} catch (OWLOntologyStorageException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
OWLOntology createOntologyFromURL(OWLOntologyManager manager, String url) {
|
||||
OWLOntology ont;
|
||||
try {
|
||||
ont = manager.createOntology(IRI.create(url));
|
||||
} catch (OWLOntologyCreationException e) {
|
||||
e.printStackTrace();
|
||||
ont = null;
|
||||
}
|
||||
return ont;
|
||||
}
|
||||
|
||||
OWLOntology displayOntology(String ont_string, OWLOntology parent_ont, String iri, String parent_iri) {
|
||||
OWLOntologyManager manager = this.getOWLModelManager().getOWLOntologyManager();
|
||||
|
||||
manager.addOntologyStorer(new HetCASLOntologyStorer());
|
||||
|
||||
System.out.println(parent_ont + ", " + parent_iri + ", " + iri);
|
||||
if (parent_ont != null && parent_iri != "" && parent_iri != iri) {
|
||||
OWLOntologyManager tempmanager = OWLManager.createOWLOntologyManager();
|
||||
tempmanager.addOntologyStorer(new HetCASLOntologyStorer());
|
||||
|
||||
manager.addIRIMapper(new SimpleIRIMapper(IRI.create("http://informatik.uni-bremen.de/hets/"+iri+".het"), IRI.create("http://foobar")));
|
||||
OWLOntology temp_ont;
|
||||
ByteArrayOutputStream outputstream = new ByteArrayOutputStream();
|
||||
temp_ont = createOntologyFromURL(tempmanager, "http://informatik.uni-bremen.de/hets/"+iri+".het");
|
||||
|
||||
System.out.println(parent_iri + ", " + parent_ont);
|
||||
tempmanager.addIRIMapper(new SimpleIRIMapper(IRI.create("http://informatik.uni-bremen.de/hets/"+parent_iri+".het"), manager.getOntologyDocumentIRI(parent_ont)));
|
||||
|
||||
tempmanager.applyChange(new AddImport(temp_ont, manager.getOWLDataFactory().getOWLImportsDeclaration(IRI.create("http://informatik.uni-bremen.de/hets/"+parent_iri+".het"))));
|
||||
|
||||
for (OWLClass cls : parent_ont.getClassesInSignature()) {
|
||||
tempmanager.addAxiom(temp_ont, manager.getOWLDataFactory().getOWLDeclarationAxiom(cls));
|
||||
}
|
||||
|
||||
saveOntologyToStream(tempmanager, temp_ont, outputstream, "http://informatik.uni-bremen.de/hets/"+parent_iri+".het#");
|
||||
|
||||
tempmanager.removeOntology(temp_ont);
|
||||
|
||||
try {
|
||||
outputstream.write(ont_string.getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ont_string = outputstream.toString();
|
||||
}
|
||||
|
||||
if (parent_iri == "") {
|
||||
parent_iri = iri;
|
||||
}
|
||||
|
||||
OWLOntology ontology1 = loadOntologyFromString(manager, ont_string, iri);
|
||||
manager.setOntologyFormat(ontology1, new HetCASLOntologyFormat("http://informatik.uni-bremen.de/hets/"+parent_iri+".het#"));
|
||||
|
||||
this.getOWLModelManager().setActiveOntology(ontology1);
|
||||
|
||||
return ontology1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
|
||||
parts = new ArrayList<String>();
|
||||
ontologies = new Hashtable<String, OWLOntology>();
|
||||
owl_parts = new ArrayList<String>();
|
||||
|
||||
Set<String> exts = new HashSet<String>();
|
||||
exts.add("het");
|
||||
exts.add("owl");
|
||||
FileInputStream file = null;
|
||||
try {
|
||||
file = new FileInputStream(UIUtil.openFile(new JFrame(), "HetCASL", "Please select a *.het file", exts));
|
||||
} catch (HeadlessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
HetCASLParser parser = new HetCASLParser(file);
|
||||
SimpleNode parseTree = null;
|
||||
try {
|
||||
parseTree = parser.LIB_DEFN();
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
int num_logics, num_spec_defs, num_specs;
|
||||
boolean is_owl = false;
|
||||
OWLOntology parent = null;
|
||||
String parent_name = "";
|
||||
String spec_name = "";
|
||||
String value;
|
||||
SimpleNode logicnode, specdefnode, specnode;
|
||||
|
||||
value = (String)((SimpleNode)parseTree).jjtGetValue(); // lib name
|
||||
num_logics = parseTree.jjtGetNumChildren();
|
||||
|
||||
parts.add("");
|
||||
parts.set(parts.size()-1, parts.get(parts.size()-1) + "library " + value + "\n\n");
|
||||
|
||||
for (int i = 0; i < num_logics; i++) {
|
||||
logicnode = (SimpleNode)parseTree.jjtGetChild(i);
|
||||
value = (String)logicnode.jjtGetValue(); // logic name
|
||||
num_spec_defs = logicnode.jjtGetNumChildren();
|
||||
|
||||
parts.set(parts.size()-1, parts.get(parts.size()-1) + "logic " + value + "\n\n");
|
||||
|
||||
System.out.println(value);
|
||||
if (value.contains("OWL")) {
|
||||
is_owl = true;
|
||||
System.out.println("is OWL");
|
||||
} else {
|
||||
is_owl = false;
|
||||
}
|
||||
|
||||
for (int j = 0; j < num_spec_defs; j++) {
|
||||
specdefnode = (SimpleNode)logicnode.jjtGetChild(j);
|
||||
value = (String)specdefnode.jjtGetValue(); // spec name
|
||||
num_specs = specdefnode.jjtGetNumChildren();
|
||||
|
||||
spec_name = value.trim();
|
||||
parts.set(parts.size()-1, parts.get(parts.size()-1) + "spec " + spec_name + " =");
|
||||
|
||||
for (int k = 0; k < num_specs; k++) {
|
||||
specnode = (SimpleNode)specdefnode.jjtGetChild(k);
|
||||
value = (String)specnode.jjtGetValue(); // spec
|
||||
|
||||
// TODO: enable printspecial
|
||||
//System.out.println(printspecial(specnode.jjtGetFirstToken()));
|
||||
|
||||
if (is_owl) {
|
||||
// check if only name
|
||||
if (value.trim().contains(" ")) {
|
||||
//System.out.println("display ontology: "+spec_name+", "+parent_name);
|
||||
parent = displayOntology(value, parent, spec_name, parent_name);
|
||||
ontologies.put(spec_name+parent_name, parent);
|
||||
owl_parts.add(spec_name);
|
||||
parts.add("");
|
||||
} else {
|
||||
parent_name = value.trim();
|
||||
parts.set(parts.size()-1, parts.get(parts.size()-1) + " " + parent_name + "\n");
|
||||
parent = ontologies.get(parent_name);
|
||||
|
||||
//System.out.println(" +++ " + parent + " " + ((String)values.get("spec")).trim());
|
||||
}
|
||||
} else {
|
||||
parts.set(parts.size()-1, parts.get(parts.size()-1) + value);
|
||||
}
|
||||
|
||||
if (specnode.toString() == "SPEC_THEN") {
|
||||
parts.set(parts.size()-1, parts.get(parts.size()-1) + "then");
|
||||
} else if (specnode.toString() == "SPEC_END") {
|
||||
parts.set(parts.size()-1, parts.get(parts.size()-1) + "end\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
parent = null;
|
||||
parent_name = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue