Skip to content

Commit

Permalink
[wordnet]add a new port (#8816)
Browse files Browse the repository at this point in the history
* [wordnet]add a new port

* [wordnet]fix-uwp
  • Loading branch information
ChaoJia authored and ras0219-msft committed Oct 31, 2019
1 parent d2cd3ad commit 6282cab
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 0 deletions.
69 changes: 69 additions & 0 deletions ports/wordnet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
cmake_minimum_required (VERSION 3.14)
project ("wordnet")
set (target_name ${CMAKE_PROJECT_NAME}) # CMAKE_PROJECT_NAME for the top-level project() call

option (BUILD_SHARED_LIBS "Create ${target_name} as a shared library" OFF)
set (CMAKE_DEBUG_POSTFIX "d" CACHE STRING "postfix for debug lib")

set (INCLUDE_DIR_BUILD "${CMAKE_CURRENT_LIST_DIR}/include")

include (GNUInstallDirs)

file (GLOB wordnet_headers ${INCLUDE_DIR_BUILD}/wn.h)
file (GLOB wordnet_srcs "lib/*.c")

add_library (${target_name} ${wordnet_srcs} ${wordnet_headers})

target_include_directories (${target_name}
PRIVATE ${INCLUDE_DIR_BUILD}
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

set_target_properties(${target_name} PROPERTIES
C_STANDARD 11
)

target_compile_definitions(${PROJECT_NAME} PUBLIC DEFAULTPATH="${WORDNET_DICT_PATH}")

if (MSVC)
set_target_properties(${target_name} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:${target_name}>
COMPILE_FLAGS "/wd4996 /wd4267 /wd4244 /wd4047"
)
target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${target_name})
endif()

install (TARGETS ${target_name} EXPORT ${target_name}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES
${wordnet_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${target_name}
CONFIGURATIONS Release
)

install (EXPORT ${target_name}-targets
FILE ${target_name}-targets.cmake
NAMESPACE ${target_name}::
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${target_name}"
)

configure_file(${target_name}-config.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${target_name}-config.cmake" @ONLY)

install(FILES
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${target_name}-config.cmake"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${target_name}"
)

install(DIRECTORY
dict/ DESTINATION ${WORDNET_DICT_PATH}
CONFIGURATIONS Release
)
install(DIRECTORY
doc/ DESTINATION ${CMAKE_INSTALL_DOCDIR}
CONFIGURATIONS Release
)
6 changes: 6 additions & 0 deletions ports/wordnet/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Source: wordnet
Version: 3.0
Description: WordNet is a large lexical database of English

Feature: dbfiles
Description: WordNet 3.1 database files
78 changes: 78 additions & 0 deletions ports/wordnet/fix_gobal_vars_uninit_local_ptr.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
diff --git a/include/wn.h b/include/wn.h
index d3ffa08..8452377 100644
--- a/include/wn.h
+++ b/include/wn.h
@@ -151,14 +151,6 @@
#define PREDICATIVE PADJ
#define IMMED_POSTNOMINAL IPADJ

-extern char *wnrelease; /* WordNet release/version number */
-
-extern char *lexfiles[]; /* names of lexicographer files */
-extern char *ptrtyp[]; /* pointer characters */
-extern char *partnames[]; /* POS strings */
-extern char partchars[]; /* single chars for each POS */
-extern char *adjclass[]; /* adjective class strings */
-extern char *frametext[]; /* text of verb frames */

/* Data structures used by search code functions. */

@@ -236,6 +228,21 @@ typedef struct {

typedef SearchResults *SearchResultsPtr;

+/* Make all the functions compatible with c++ files */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char* wnrelease; /* WordNet release/version number */
+
+extern char* lexfiles[]; /* names of lexicographer files */
+extern char* ptrtyp[]; /* pointer characters */
+extern char* partnames[]; /* POS strings */
+extern char partchars[]; /* single chars for each POS */
+extern char* adjclass[]; /* adjective class strings */
+extern char* frametext[]; /* text of verb frames */
+
+
/* Global variables and flags */

extern SearchResults wnresults; /* structure containing results of search */
@@ -271,11 +278,6 @@ extern int default_display_message(char *);
extern int (*display_message)(char *);


-/* Make all the functions compatible with c++ files */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/* External library function prototypes */

/*** Search and database functions (search.c) ***/
diff --git a/lib/search.c b/lib/search.c
index 1cdedc3..72c4bb5 100644
--- a/lib/search.c
+++ b/lib/search.c
@@ -1256,7 +1256,7 @@ static void add_relatives(int pos, IndexPtr idx, int rel1, int rel2)
{
int i;
struct relgrp *rel, *last, *r;
-
+ last = NULL;
/* If either of the new relatives are already in a relative group,
then add the other to the existing group (transitivity).
Otherwise create a new group and add these 2 senses to it. */
@@ -1281,8 +1281,9 @@ static void add_relatives(int pos, IndexPtr idx, int rel1, int rel2)
rel->senses[rel1] = rel->senses[rel2] = 1;
if (rellist == NULL)
rellist = rel;
- else
- last->next = rel;
+ else if (last) {
+ last->next = rel;
+ }
}

static struct relgrp *mkrellist(void)
54 changes: 54 additions & 0 deletions ports/wordnet/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
include(vcpkg_common_functions)

vcpkg_check_linkage(ONLY_STATIC_LIBRARY)

set(VERSION 3.0)

vcpkg_download_distfile(ARCHIVE
URLS "http://wordnetcode.princeton.edu/${VERSION}/WordNet-${VERSION}.tar.gz"
FILENAME "wordnet-${VERSION}.tar.gz"
SHA512 9539bc016d710f31d65072bbf5068edffcd735978d8cc6f1b361b19428b97546ef6c7e246e1b6f2ff4557a0885a8305341e35173a6723f0740dda18d097ca248
)

vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE}
REF ${VERSION}
PATCHES
fix_gobal_vars_uninit_local_ptr.patch
)

file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
file(COPY ${CMAKE_CURRENT_LIST_DIR}/wordnet-config.cmake.in DESTINATION ${SOURCE_PATH})

if("dbfiles" IN_LIST FEATURES)
vcpkg_download_distfile(WORDNET_DICT_DBFILES
URLS "http://wordnetcode.princeton.edu/wn3.1.dict.tar.gz"
FILENAME "wordnet-cache/wn3.1.dict.tar.gz"
SHA512 16dca17a87026d8a0b7b4758219cd21a869c3ef3da23ce7875924546f2eacac4c2f376cb271b798b2c458fe8c078fb43d681356e3d9beef40f4bd88d3579394f
)
file(REMOVE_RECURSE "${SOURCE_PATH}/dict/")
vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH WORDNET_DICT_DBFILES_EX
ARCHIVE ${WORDNET_DICT_DBFILES}
REF 3.1
WORKING_DIRECTORY ${SOURCE_PATH}
)
file(RENAME ${WORDNET_DICT_DBFILES_EX} "${SOURCE_PATH}/dict")
endif()

set (WORDNET_DICT_PATH "${CURRENT_PACKAGES_DIR}/tools/${PORT}/dict")

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS -DWORDNET_DICT_PATH=${WORDNET_DICT_PATH}
)

vcpkg_install_cmake()
vcpkg_copy_pdbs()
vcpkg_fixup_cmake_targets()

# Handle copyright
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/wordnet RENAME copyright)

14 changes: 14 additions & 0 deletions ports/wordnet/wordnet-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Config file for the wordnet package

get_filename_component(_WORDNET_PREFIX_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)

set (_TARGET_NAME "wordnet")

set (WORDNET_DICT_PATH @WORDNET_DICT_PATH@)
message (STATUS "WORDNET_DICT_PATH: @WORDNET_DICT_PATH@")

# IMPORTED targets for wordnet
include("${_WORDNET_PREFIX_DIR}/${_TARGET_NAME}-targets.cmake")

set(_WORDNET_PREFIX_DIR)
set(_TARGET_NAME)

0 comments on commit 6282cab

Please sign in to comment.