diff options
author | Sid Jain <sija@microsoft.com> | 2020-10-14 16:30:25 +0300 |
---|---|---|
committer | Sid Jain <sija@microsoft.com> | 2020-10-14 16:30:25 +0300 |
commit | a312312e7806942ea9535a5e96e5ec04e0d11f62 (patch) | |
tree | 46caecf463cc0b9f5d25db22f1b3ef11a15a8129 | |
parent | 5579cbd463e01a43efeed2205b57837d1a1cc0e3 (diff) |
windows build and managed clr
-rw-r--r-- | contrib/other-builds/MosesManagedDLL/ManagedMoses.cpp | 116 | ||||
-rw-r--r-- | contrib/other-builds/MosesManagedDLL/MosesManagedDLL.vcxproj | 170 | ||||
-rw-r--r-- | contrib/other-builds/MosesManagedDLL/MosesManagedDLL.vcxproj.filters | 22 | ||||
-rw-r--r-- | contrib/other-builds/moses2wrapper/ManagedMoses.cpp | 36 | ||||
-rw-r--r-- | contrib/other-builds/moses2wrapper/moses2wrapper.vcxproj | 176 | ||||
-rw-r--r-- | moses2/Main.cpp | 6 | ||||
-rw-r--r-- | moses2/Moses2Wrapper.cpp | 20 | ||||
-rw-r--r-- | moses2/Moses2Wrapper.h | 16 | ||||
-rw-r--r-- | moses2/TranslationTask.cpp | 11 | ||||
-rw-r--r-- | moses2/TranslationTask.h | 1 | ||||
-rw-r--r-- | moses2/server/Server.cpp | 4 |
11 files changed, 573 insertions, 5 deletions
diff --git a/contrib/other-builds/MosesManagedDLL/ManagedMoses.cpp b/contrib/other-builds/MosesManagedDLL/ManagedMoses.cpp new file mode 100644 index 000000000..0ba728360 --- /dev/null +++ b/contrib/other-builds/MosesManagedDLL/ManagedMoses.cpp @@ -0,0 +1,116 @@ +#define NOMINMAX // Windows max macro collides with std:: +#include <Windows.h> +#include <memory> +#include <vcclr.h> +#include <msclr/marshal_cppstd.h> +#include "Moses2Wrapper.h" + +using namespace System; +using namespace msclr::interop; + + +namespace Moses { + public ref class Moses2Wrapper + { + public: + Moses2Wrapper(String^ filePath) { + const std::string standardString = marshal_as<std::string>(filePath); + m_pWrapper = new Moses2::Moses2Wrapper(standardString); + } + ~Moses2Wrapper() { this->!Moses2Wrapper(); } + String^ Translate(String^ input) { + const std::string standardString = marshal_as<std::string>(input); + std::string output = m_pWrapper->Translate(standardString); + //Console::WriteLine(output); + String^ str = gcnew String(output.c_str()); + return str; + } + + protected: + !Moses2Wrapper() { delete m_pWrapper; m_pWrapper = nullptr; } + private: + Moses2::Moses2Wrapper *m_pWrapper; + }; +} +/* +public class ManagedMoses +{ + Moses2::Moses2Wrapper *m_Instance; +public: + ManagedMoses(String^ filepath) { + const std::string standardString = marshal_as<std::string>(filepath); + m_Instance = new Moses2::Moses2Wrapper(standardString); + + } + String^ Translate(String^ input){ + const std::string standardString = marshal_as<std::string>(input); + std::string output = m_Instance->Translate(standardString); + //Console::WriteLine(output); + String^ str = gcnew String(output.c_str()); + return str; + } +}; + + +/* +#include <winsock2.h> +#ifndef WIN32 +#define WIN32 +#endif +#include <msclr/marshal_cppstd.h> +#include "legacy/Parameter.h" +#include "System.h" + +using namespace System; +using namespace msclr::interop; + +// A wrapper around Faiss that lets you build indexes +// Right now just proof-of-concept code to makes sure it all works from C#, +// eventually may want to rework the interface, or possibly look at extending +// FaissSharp to support the windows dll + +namespace Moses { + + + + public ref class Parameter + { + public: + Parameter() { m_pWrapper = new Moses2::Parameter(); } + ~Parameter() { this->!Parameter(); } + bool LoadParams(String^ filePath) { + const std::string standardString = marshal_as<std::string>(filePath); + auto flag = m_pWrapper->LoadParam(standardString); + return bool(flag); + } + Parameter* GetInstance() + { + return m_pWrapper; + } + protected: + !Parameter() { delete m_pWrapper; m_pWrapper = nullptr; } + private: + Moses2::Parameter* m_pWrapper; + }; + + + public ref class System { + public: + System(const Parameter^ paramsArg) { + new Moses2::System(paramsArg->GetInstance()); + } + ~System() { this->!System(); } + protected: + !System() { delete m_sWrapper; m_sWrapper = nullptr; } + private: + Moses2::System* m_sWrapper; + Moses2::Parameter* paramArgs; + }; + + + + + +} + +*/
\ No newline at end of file diff --git a/contrib/other-builds/MosesManagedDLL/MosesManagedDLL.vcxproj b/contrib/other-builds/MosesManagedDLL/MosesManagedDLL.vcxproj new file mode 100644 index 000000000..804bcc011 --- /dev/null +++ b/contrib/other-builds/MosesManagedDLL/MosesManagedDLL.vcxproj @@ -0,0 +1,170 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>16.0</VCProjectVersion> + <Keyword>Win32Proj</Keyword> + <ProjectGuid>{5fb67144-27c9-4993-a084-e2097ffcc4fe}</ProjectGuid> + <RootNamespace>MosesManagedDLL</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + <CLRSupport>true</CLRSupport> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;_DEBUG;MOSESMANAGEDDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableUAC>false</EnableUAC> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;NDEBUG;MOSESMANAGEDDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableUAC>false</EnableUAC> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_DEBUG;MOSESMANAGEDDLL_EXPORTS;NO_COMPACT_TABLES;HAVE_CMPHXXX;MAX_NUM_FACTORS=4;KENLM_MAX_ORDER=6;_USE_MATH_DEFINES;NOMINMAX;WITH_THREADS;NO_PIPES;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>false</ConformanceMode> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + <AdditionalIncludeDirectories>F:\boost_1_72_0;D:\moses-mstranslator;D:\xmlrpc-c-1.51.06\include;D:\moses-mstranslator\moses2</AdditionalIncludeDirectories> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableUAC>false</EnableUAC> + <AdditionalLibraryDirectories>D:\zlib-1.2.8\contrib\vstudio\vc11\x64\ZlibDllRelease;D:\xmlrpc-c-1.51.06\bin\Debug-Static-x64;C:\Users\sija\Downloads\2.0.2\bonitao-cmph-e5f83da\Debug;D:\zlib_1_2_8_msvc2015_64\msvc2015_64\lib\zlib;D:\mman-win32-master\x64\Release;F:\boost_1_72_0\lib64-msvc-14.2;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <AdditionalDependencies>libxmlrpc.lib;libxmlrpc_server_abyss.lib;libxmlrpc_server.lib;libxmlrpc_abyss.lib;libxmlrpc_util.lib;libxmlrpc_xmlparse.lib;libxmlrpc_xmltok.lib;libxmlrpc++.lib;zlibwapi.lib;mman.lib;cmph.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>NDEBUG;MOSESMANAGEDDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableUAC>false</EnableUAC> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="ManagedMoses.cpp" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\moses2\moses2.vcxproj"> + <Project>{b4304e97-d37f-4022-bd03-841a4faee398}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/contrib/other-builds/MosesManagedDLL/MosesManagedDLL.vcxproj.filters b/contrib/other-builds/MosesManagedDLL/MosesManagedDLL.vcxproj.filters new file mode 100644 index 000000000..8bd68daf0 --- /dev/null +++ b/contrib/other-builds/MosesManagedDLL/MosesManagedDLL.vcxproj.filters @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="ManagedMoses.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/contrib/other-builds/moses2wrapper/ManagedMoses.cpp b/contrib/other-builds/moses2wrapper/ManagedMoses.cpp new file mode 100644 index 000000000..adba8845f --- /dev/null +++ b/contrib/other-builds/moses2wrapper/ManagedMoses.cpp @@ -0,0 +1,36 @@ +#include <msclr/marshal_cppstd.h> +#include "legacy\Parameter.h" +#include "System.h" + +using namespace System; +using namespace msclr::interop; + +// A wrapper around Faiss that lets you build indexes +// Right now just proof-of-concept code to makes sure it all works from C#, +// eventually may want to rework the interface, or possibly look at extending +// FaissSharp to support the windows dll + +namespace Moses { + + public ref class System + { + + public: + + }; + + public ref class Parameter + { + public: + Parameter() { m_pWrapper = new Moses2::Parameter(); } + ~Parameter() { this->!Parameter(); } + + + + private: + // Review: I'm not using e.g. unique_ptr here because I don't know the lifetime + // semantics behind ref classes. + Moses2::Parameter* m_pWrapper; + }; + +} diff --git a/contrib/other-builds/moses2wrapper/moses2wrapper.vcxproj b/contrib/other-builds/moses2wrapper/moses2wrapper.vcxproj new file mode 100644 index 000000000..aa75c8dab --- /dev/null +++ b/contrib/other-builds/moses2wrapper/moses2wrapper.vcxproj @@ -0,0 +1,176 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>16.0</VCProjectVersion> + <Keyword>Win32Proj</Keyword> + <ProjectGuid>{a190cd7d-ee0a-4eaa-8093-a751df1d4157}</ProjectGuid> + <RootNamespace>moses2wrapper</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v142</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;_DEBUG;MOSES2WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableUAC>false</EnableUAC> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;NDEBUG;MOSES2WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableUAC>false</EnableUAC> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_DEBUG;MOSES2WRAPPER_EXPORTS;_WINDOWS;_USRDLL;NO_COMPACT_TABLES;HAVE_CMPHXXX;MAX_NUM_FACTORS=4;KENLM_MAX_ORDER=6;_USE_MATH_DEFINES;NOMINMAX;WITH_THREADS;NO_PIPES;_WIN32;WIN32;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + <CompileAsManaged>true</CompileAsManaged> + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> + <DiagnosticsFormat>Classic</DiagnosticsFormat> + <ExceptionHandling>Async</ExceptionHandling> + <BasicRuntimeChecks>Default</BasicRuntimeChecks> + <StringPooling>true</StringPooling> + <FunctionLevelLinking>true</FunctionLevelLinking> + <RuntimeTypeInfo>true</RuntimeTypeInfo> + <AdditionalOptions>/Zc:twoPhase- %(AdditionalOptions)</AdditionalOptions> + <AdditionalIncludeDirectories>F:\boost_1_72_0;D:\mman-win32-master;D:\zlib-1.2.8;D:\cmph-2.0.2;D:\moses-mstranslator;D:\xmlrpc-c-1.51.06\include;D:\moses-mstranslator\moses2</AdditionalIncludeDirectories> + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableUAC>false</EnableUAC> + <AdditionalLibraryDirectories>F:\boost_1_72_0\lib64-msvc-14.2;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>NDEBUG;MOSES2WRAPPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + <PrecompiledHeader>Use</PrecompiledHeader> + <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableUAC>false</EnableUAC> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ProjectReference Include="..\moses2\moses2.vcxproj"> + <Project>{b4304e97-d37f-4022-bd03-841a4faee398}</Project> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <ClCompile Include="ManagedMoses.cpp" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/moses2/Main.cpp b/moses2/Main.cpp index cf833760a..7054ec4ce 100644 --- a/moses2/Main.cpp +++ b/moses2/Main.cpp @@ -6,7 +6,7 @@ #include "Phrase.h" #include "TranslationTask.h" #include "MemPoolAllocator.h" -#include "server/Server.h" +//#include "server/Server.h" #include "legacy/InputFileStream.h" #include "legacy/Parameter.h" #include "legacy/ThreadPool.h" @@ -59,8 +59,8 @@ int main(int argc, char** argv) //////////////////////////////////////////////////////////////////////////////////////////////// void run_as_server(Moses2::System &system) { - Moses2::Server server(system.options.server, system); - server.run(system); // actually: don't return. see Server::run() + //Moses2::Server server(system.options.server, system); + //server.run(system); // actually: don't return. see Server::run() } //////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/moses2/Moses2Wrapper.cpp b/moses2/Moses2Wrapper.cpp new file mode 100644 index 000000000..2d7155e03 --- /dev/null +++ b/moses2/Moses2Wrapper.cpp @@ -0,0 +1,20 @@ +#include "Moses2Wrapper.h" +#include "System.h" +#include "legacy/Parameter.h" +#include "TranslationTask.h" +using namespace std; +namespace Moses2 { + Moses2Wrapper::Moses2Wrapper(const std::string &filePath) { + m_param = new Parameter(); + m_param->LoadParam(filePath); + m_system = new System(*m_param); + } + std::string Moses2Wrapper::Translate(const std::string &input) { + //create id + long a = 11234567; + TranslationTask task(*m_system, input, a); + std::string translation = task.RunTranslation(); + //delete translation; + return translation; + } +}
\ No newline at end of file diff --git a/moses2/Moses2Wrapper.h b/moses2/Moses2Wrapper.h new file mode 100644 index 000000000..01d021145 --- /dev/null +++ b/moses2/Moses2Wrapper.h @@ -0,0 +1,16 @@ +#pragma once +#include <string> +namespace Moses2 { + class Parameter; + class System; + class Moses2Wrapper + { + Parameter *m_param; + System *m_system; + + public: + Moses2Wrapper(const std::string &filePath); + std::string Translate(const std::string &input); + }; + +}
\ No newline at end of file diff --git a/moses2/TranslationTask.cpp b/moses2/TranslationTask.cpp index 219d9ffcb..0032ab0b0 100644 --- a/moses2/TranslationTask.cpp +++ b/moses2/TranslationTask.cpp @@ -23,7 +23,18 @@ TranslationTask::TranslationTask(System &system, TranslationTask::~TranslationTask() { } +std::string TranslationTask::RunTranslation() +{ + m_mgr->Decode(); + + string out; + out = m_mgr->OutputBest() + "\n"; + + + delete m_mgr; + return out; +} void TranslationTask::Run() { diff --git a/moses2/TranslationTask.h b/moses2/TranslationTask.h index bf2330357..e683e1174 100644 --- a/moses2/TranslationTask.h +++ b/moses2/TranslationTask.h @@ -16,6 +16,7 @@ public: TranslationTask(System &system, const std::string &line, long translationId); virtual ~TranslationTask(); virtual void Run(); + virtual std::string RunTranslation(); protected: ManagerBase *m_mgr; diff --git a/moses2/server/Server.cpp b/moses2/server/Server.cpp index 57218c374..2da72270a 100644 --- a/moses2/server/Server.cpp +++ b/moses2/server/Server.cpp @@ -19,12 +19,12 @@ Server::Server(ServerOptions &server_options, System &system) :m_server_options(server_options) ,m_translator(new Translator(*this, system)) { - m_registry.addMethod("translate", m_translator); + // m_registry.addMethod("translate", m_translator); } Server::~Server() { - unlink(m_pidfile.c_str()); + //unlink(m_pidfile.c_str()); } void Server::run(System &system) |