You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2007/02/16 00:03:14 UTC

svn commit: r508230 - in /incubator/uima/uimacpp/trunk/examples/tutorial: ./ README descriptors/ descriptors/MeetingAnnotatorCPP.xml src/ src/MeetingAnnotator.cpp src/MeetingAnnotator.mak src/MeetingAnnotator.vcproj

Author: eae
Date: Thu Feb 15 15:03:13 2007
New Revision: 508230

URL: http://svn.apache.org/viewvc?view=rev&rev=508230
Log:
UIMA-276 - Add the C++ annotator source, make and descriptor files

Added:
    incubator/uima/uimacpp/trunk/examples/tutorial/
    incubator/uima/uimacpp/trunk/examples/tutorial/README
    incubator/uima/uimacpp/trunk/examples/tutorial/descriptors/
    incubator/uima/uimacpp/trunk/examples/tutorial/descriptors/MeetingAnnotatorCPP.xml
    incubator/uima/uimacpp/trunk/examples/tutorial/src/
    incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.cpp   (with props)
    incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.mak
    incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.vcproj   (with props)

Added: incubator/uima/uimacpp/trunk/examples/tutorial/README
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/examples/tutorial/README?view=auto&rev=508230
==============================================================================
--- incubator/uima/uimacpp/trunk/examples/tutorial/README (added)
+++ incubator/uima/uimacpp/trunk/examples/tutorial/README Thu Feb 15 15:03:13 2007
@@ -0,0 +1,7 @@
+This directory contains a C++ version of one of the Java annotations in the
+UIMA tutorial. The descriptor file MeetingAnnotatorCPP.xml assumes that the
+uimacpp SDK is installed in $UIMA_HOME/uimacpp.
+
+The Java SDK also adds $UIMA_HOME/uimacpp/examples/tutorial/src to the
+appropriate native load shared library path so that the C++ annotator will be
+found when run using the Java tutorial.

Added: incubator/uima/uimacpp/trunk/examples/tutorial/descriptors/MeetingAnnotatorCPP.xml
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/examples/tutorial/descriptors/MeetingAnnotatorCPP.xml?view=auto&rev=508230
==============================================================================
--- incubator/uima/uimacpp/trunk/examples/tutorial/descriptors/MeetingAnnotatorCPP.xml (added)
+++ incubator/uima/uimacpp/trunk/examples/tutorial/descriptors/MeetingAnnotatorCPP.xml Thu Feb 15 15:03:13 2007
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+	Descriptor for a primitive TAE that uses the TutorialDateTime annotator
+-->
+<taeDescription xmlns="http://uima.apache.org/resourceSpecifier">
+	<frameworkImplementation>org.apache.uima.cpp</frameworkImplementation>
+	<primitive>true</primitive>
+	<annotatorImplementationName>MeetingAnnotator</annotatorImplementationName>
+
+
+	<analysisEngineMetaData>
+		<name>Meeting Annotator</name>
+		<description>Detects meetings from co-occurrences of room numbers, dates, and times</description>
+		<version>1.0</version>
+		<vendor>IBM</vendor>
+
+		<configurationParameters>
+			<configurationParameter>
+				<name>WindowSize</name>
+				<description>Maximum number of characters within which a room number, a date, and two times must occur for a meeting annotation to be created.</description>
+				<type>Integer</type>
+				<multiValued>false</multiValued>
+				<mandatory>true</mandatory>
+			</configurationParameter>
+		</configurationParameters>
+
+		<configurationParameterSettings>
+			<nameValuePair>
+				<name>WindowSize</name>
+				<value>
+					<integer>200</integer>
+				</value>
+			</nameValuePair>
+		</configurationParameterSettings>
+
+		<!--
+			TypeSystem Definition
+		-->
+
+		<typeSystemDescription>
+		  <imports>
+		    <import location="../../../../examples/descriptors/tutorial/ex4/TutorialTypeSystem.xml"/>
+		  </imports>
+		</typeSystemDescription>
+
+
+
+		<!--
+			Capabilities: Inputs, Outputs, and Preconditions
+		-->
+		<capabilities>
+			<capability>
+				<inputs>
+					<type allAnnotatorFeatures="true">org.apache.uima.tutorial.RoomNumber</type>
+					<type allAnnotatorFeatures="true">org.apache.uima.tutorial.TimeAnnot</type>
+					<type allAnnotatorFeatures="true">org.apache.uima.tutorial.DateAnnot</type>
+				</inputs>
+				<outputs>
+					<type allAnnotatorFeatures="true">org.apache.uima.tutorial.Meeting</type>
+				</outputs>
+				<languagesSupported>
+					<language>en</language>
+				</languagesSupported>
+			</capability>
+		</capabilities>
+
+	</analysisEngineMetaData>
+</taeDescription>

Added: incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.cpp?view=auto&rev=508230
==============================================================================
--- incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.cpp (added)
+++ incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.cpp Thu Feb 15 15:03:13 2007
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include "uima/api.hpp"
+using namespace uima;
+
+class MeetingAnnotator : public Annotator {
+private:
+  //config param window size
+  int mWindowSize;
+
+  //Input types
+  Type roomNumberT;
+  Type dateT;
+  Type timeT;
+
+  //output type and its features
+  Type meetingT;
+  Feature roomF;
+  Feature dateF;
+  Feature startTimeF;
+  Feature endTimeF;
+
+
+public:
+
+  MeetingAnnotator(void)
+  {
+    cout << "MeetingAnnotator: Constructor" << endl;
+  }
+
+  ~MeetingAnnotator(void)
+  {
+    cout << "MeetingAnnotator: Destructor" << endl;
+  }
+
+  /** */
+  TyErrorId initialize(AnnotatorContext & rclAnnotatorContext)
+  {
+    cout << "MeetingAnnotator: initialize()" << endl;
+
+    if (!rclAnnotatorContext.isParameterDefined("WindowSize") ||
+	rclAnnotatorContext.extractValue("WindowSize", mWindowSize) != UIMA_ERR_NONE) {
+      /* log the error condition */
+      rclAnnotatorContext.getLogger().logError("Required configuration parameter \"WindowSize\" not found in component descriptor");
+      cout << "initialize() - Error. See logfile." << endl;
+      return UIMA_ERR_USER_ANNOTATOR_COULD_NOT_INIT;
+    }
+
+	if (mWindowSize < 50) {
+      rclAnnotatorContext.getLogger().logWarning("WindowSize may be too narrow");
+    }
+
+    /* log the configuration parameter setting */
+	std::stringstream ss;
+	std::string str;
+	ss << mWindowSize;
+	ss >> str;
+    rclAnnotatorContext.getLogger().logMessage("WindowSize = '" + str + "'");
+
+    cout << "initialize() .. mWindowSize.getBuffer: "
+	 << mWindowSize << endl;
+
+    return (TyErrorId)UIMA_ERR_NONE;
+  }
+
+  /** */
+  TyErrorId typeSystemInit(TypeSystem const & crTypeSystem) {
+    cout << " typeSystemInit()" << endl;
+
+    //input types
+    roomNumberT =  crTypeSystem.getType("org.apache.uima.tutorial.RoomNumber");
+    dateT =  crTypeSystem.getType("org.apache.uima.tutorial.DateAnnot");
+    timeT =  crTypeSystem.getType("org.apache.uima.tutorial.TimeAnnot");
+
+    //output types and features
+    meetingT =  crTypeSystem.getType("org.apache.uima.tutorial.Meeting");
+
+    if ( !(meetingT.isValid() && roomNumberT.isValid() && dateT.isValid() && timeT.isValid()) ) {
+        getAnnotatorContext().getLogger().logError("typeSystemInit() Error getting Type objects");
+
+	cout << "typeSystemInit() Error getting Type object" << endl;
+	 return (TyErrorId) UIMA_ERR_RESMGR_INVALID_RESOURCE;
+    }
+
+    //get features
+    roomF = meetingT.getFeatureByBaseName("room");
+    dateF = meetingT.getFeatureByBaseName("date");
+    startTimeF = meetingT.getFeatureByBaseName("startTime");
+    endTimeF = meetingT.getFeatureByBaseName("endTime");
+
+    if ( !(roomF.isValid() && dateF.isValid() && startTimeF.isValid() && endTimeF.isValid() ) ) {
+	  getAnnotatorContext().getLogger().logError("typeSystemInit() Error getting Feature objects");
+	  cout << "typeSystemInit() Error getting Feature  object" << endl;
+	 return (TyErrorId) UIMA_ERR_RESMGR_INVALID_RESOURCE;
+  }
+
+    return (TyErrorId)UIMA_ERR_NONE;
+  }
+
+  /** */
+  TyErrorId destroy()
+  {
+    cout << "MeetingAnnotator: destroy()" << endl;
+    return (TyErrorId)UIMA_ERR_NONE;
+  }
+
+  /** */
+  TyErrorId process(CAS & tcas, ResultSpecification const & crResultSpecification)
+  {
+    cout << "MeetingAnnotator: process()" << endl;
+
+    //get annotation indexes
+    FSIndexRepository & indexes = tcas.getIndexRepository();
+
+    ANIndex roomNumberIndex = tcas.getAnnotationIndex(roomNumberT);
+    ANIndex dateIndex = tcas.getAnnotationIndex(dateT);
+    ANIndex timeIndex = tcas.getAnnotationIndex(timeT);
+
+    //store end position of last meeting we identified, to prevent multiple
+    //annotations over same span
+    int lastMeetingEnd = -1;
+
+    //iterate over all combinations
+    ANIterator roomNumberIter = roomNumberIndex.iterator();
+    roomNumberIter.moveToFirst();
+    while (roomNumberIter.isValid()) {
+      AnnotationFS room = roomNumberIter.get();
+
+      ANIterator dateIter = dateIndex.iterator();
+      dateIter.moveToFirst();
+
+      while (dateIter.isValid()) {
+        AnnotationFS date = dateIter.get();
+        ANIterator time1Iter = timeIndex.iterator();
+        time1Iter.moveToFirst();
+
+        while (time1Iter.isValid()) {
+          AnnotationFS time1 = time1Iter.get();
+          ANIterator time2Iter = timeIndex.iterator();
+          time2Iter.moveToFirst();
+
+          while (time2Iter.isValid()) {
+            AnnotationFS time2 = time2Iter.get();
+
+            //times must be different annotations
+            if (time1 != time2) {
+              //compute the begin and end of the span
+              int minBegin = min(
+				  min(time1.getBeginPosition(), time2.getBeginPosition()),
+				  min(date.getBeginPosition(), room.getBeginPosition()));
+
+			  int maxEnd = max(
+		  		  max(time1.getEndPosition(), time2.getEndPosition()),
+		  		  max(date.getEndPosition(), room.getEndPosition()));
+
+			  //span must be smaller than the window size?
+			  if (maxEnd - minBegin < mWindowSize) {
+				//span must not overlap the last annotation we made
+				if (minBegin > lastMeetingEnd) {
+				  //annotate
+				  //Create Meeting FS and set the begin and end features
+				  AnnotationFS mtg = tcas.createAnnotation(meetingT, minBegin, maxEnd);
+				  //Set other four features
+				  mtg.setFSValue(roomF, room);
+				  mtg.setFSValue(dateF, date);
+				  mtg.setFSValue(startTimeF, time1);
+				  mtg.setFSValue(endTimeF, time2);
+
+				  //add annotation to the index
+				  indexes.addFS(mtg);
+				  lastMeetingEnd = maxEnd;
+				}
+			  }
+			}
+			time2Iter.moveToNext();
+			}
+			time1Iter.moveToNext();
+		  }
+		  dateIter.moveToNext();
+		}
+		roomNumberIter.moveToNext();
+	}
+	return (TyErrorId)UIMA_ERR_NONE;
+  }
+};
+
+
+// This macro exports an entry point that is used to create the annotator.
+
+MAKE_AE(MeetingAnnotator);
+

Propchange: incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.mak
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.mak?view=auto&rev=508230
==============================================================================
--- incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.mak (added)
+++ incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.mak Thu Feb 15 15:03:13 2007
@@ -0,0 +1,25 @@
+#####################################
+# UNIX Makefile for a UIMACPP annotator
+#####################################
+
+# name of the annotator to be created
+TARGET_FILE=MeetingAnnotator
+
+# list of user's object files to be linked when building the annotator
+OBJS=MeetingAnnotator.o
+
+#Use this var to pass additional user-defined parameters to the compiler
+USER_CFLAGS=
+
+#Use this var to pass additional user-defined parameters to the linker
+USER_LINKFLAGS=
+
+# Set DEBUG=1 for a debug build (if not 1 a ship build will result)
+DEBUG=1
+
+# Set DLL_BUILD=1 to build an annotator (shared library)
+#    if not 1 an executable binary will be built
+DLL_BUILD=1
+
+# include file with generic compiler instructions
+include $(UIMACPP_HOME)/lib/base.mak

Added: incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.vcproj
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.vcproj?view=auto&rev=508230
==============================================================================
--- incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.vcproj (added)
+++ incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.vcproj Thu Feb 15 15:03:13 2007
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="MeetingAnnotator"
+	ProjectGUID="{69C8A769-7CEC-4D2A-B189-FE19606577B7}"
+	RootNamespace="MeetingAnnotator"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(InputDir)"
+			IntermediateDirectory="$(ConfigurationName)\$(ProjectName)"
+			ConfigurationType="2"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="&quot;$(UIMACPP_HOME)\include&quot;;&quot;$(UIMACPP_HOME)\include\apr&quot;"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL"
+				MinimalRebuild="TRUE"
+				ExceptionHandling="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				ProgramDataBaseFileName="$(IntDir)/$TargetName).pdb"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="libapr$(APR_VER).lib xerces-c_2.lib icuuc.lib uimaD.lib"
+				OutputFile="$(OutDir)/MeetingAnnotator.dll"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="&quot;$(UIMACPP_HOME)\lib&quot;"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+				SubSystem="2"
+				ImportLibrary="$(OutDir)/$(TargetName).lib"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(InputDir)"
+			IntermediateDirectory="$(ConfigurationName)\$(ProjectName)"
+			ConfigurationType="2"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="3"
+				AdditionalIncludeDirectories="&quot;$(UIMACPP_HOME)\include&quot;;&quot;$(UIMACPP_HOME)\include\apr&quot;"
+				PreprocessorDefinitions="TRACEOFF;NDEBUG;WIN32;_WINDOWS;_USRDLL"
+				MinimalRebuild="FALSE"
+				ExceptionHandling="TRUE"
+				BasicRuntimeChecks="0"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				ProgramDataBaseFileName="$(IntDir)/$(TargetName).pdb"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="libapr$(APR_VER).lib xerces-c_2.lib icuuc.lib uima.lib"
+				OutputFile="$(OutDir)/MeetingAnnotator.dll"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="&quot;$(UIMACPP_HOME)\lib&quot;"
+				GenerateDebugInformation="FALSE"
+				ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				ImportLibrary="$(OutDir)/$(TargetName).lib"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath=".\MeetingAnnotator.cpp">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

Propchange: incubator/uima/uimacpp/trunk/examples/tutorial/src/MeetingAnnotator.vcproj
------------------------------------------------------------------------------
    svn:eol-style = CRLF