Skip to content

Commit 6282cab

Browse files
ChaoJiaras0219-msft
authored andcommitted
[wordnet]add a new port (#8816)
* [wordnet]add a new port * [wordnet]fix-uwp
1 parent d2cd3ad commit 6282cab

File tree

5 files changed

+221
-0
lines changed

5 files changed

+221
-0
lines changed

ports/wordnet/CMakeLists.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
cmake_minimum_required (VERSION 3.14)
2+
project ("wordnet")
3+
set (target_name ${CMAKE_PROJECT_NAME}) # CMAKE_PROJECT_NAME for the top-level project() call
4+
5+
option (BUILD_SHARED_LIBS "Create ${target_name} as a shared library" OFF)
6+
set (CMAKE_DEBUG_POSTFIX "d" CACHE STRING "postfix for debug lib")
7+
8+
set (INCLUDE_DIR_BUILD "${CMAKE_CURRENT_LIST_DIR}/include")
9+
10+
include (GNUInstallDirs)
11+
12+
file (GLOB wordnet_headers ${INCLUDE_DIR_BUILD}/wn.h)
13+
file (GLOB wordnet_srcs "lib/*.c")
14+
15+
add_library (${target_name} ${wordnet_srcs} ${wordnet_headers})
16+
17+
target_include_directories (${target_name}
18+
PRIVATE ${INCLUDE_DIR_BUILD}
19+
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
20+
)
21+
22+
set_target_properties(${target_name} PROPERTIES
23+
C_STANDARD 11
24+
)
25+
26+
target_compile_definitions(${PROJECT_NAME} PUBLIC DEFAULTPATH="${WORDNET_DICT_PATH}")
27+
28+
if (MSVC)
29+
set_target_properties(${target_name} PROPERTIES
30+
VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:${target_name}>
31+
COMPILE_FLAGS "/wd4996 /wd4267 /wd4244 /wd4047"
32+
)
33+
target_compile_definitions(${PROJECT_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
34+
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${target_name})
35+
endif()
36+
37+
install (TARGETS ${target_name} EXPORT ${target_name}-targets
38+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
39+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
40+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
41+
)
42+
43+
install(FILES
44+
${wordnet_headers}
45+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${target_name}
46+
CONFIGURATIONS Release
47+
)
48+
49+
install (EXPORT ${target_name}-targets
50+
FILE ${target_name}-targets.cmake
51+
NAMESPACE ${target_name}::
52+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${target_name}"
53+
)
54+
55+
configure_file(${target_name}-config.cmake.in "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${target_name}-config.cmake" @ONLY)
56+
57+
install(FILES
58+
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${target_name}-config.cmake"
59+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${target_name}"
60+
)
61+
62+
install(DIRECTORY
63+
dict/ DESTINATION ${WORDNET_DICT_PATH}
64+
CONFIGURATIONS Release
65+
)
66+
install(DIRECTORY
67+
doc/ DESTINATION ${CMAKE_INSTALL_DOCDIR}
68+
CONFIGURATIONS Release
69+
)

ports/wordnet/CONTROL

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Source: wordnet
2+
Version: 3.0
3+
Description: WordNet is a large lexical database of English
4+
5+
Feature: dbfiles
6+
Description: WordNet 3.1 database files
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
diff --git a/include/wn.h b/include/wn.h
2+
index d3ffa08..8452377 100644
3+
--- a/include/wn.h
4+
+++ b/include/wn.h
5+
@@ -151,14 +151,6 @@
6+
#define PREDICATIVE PADJ
7+
#define IMMED_POSTNOMINAL IPADJ
8+
9+
-extern char *wnrelease; /* WordNet release/version number */
10+
-
11+
-extern char *lexfiles[]; /* names of lexicographer files */
12+
-extern char *ptrtyp[]; /* pointer characters */
13+
-extern char *partnames[]; /* POS strings */
14+
-extern char partchars[]; /* single chars for each POS */
15+
-extern char *adjclass[]; /* adjective class strings */
16+
-extern char *frametext[]; /* text of verb frames */
17+
18+
/* Data structures used by search code functions. */
19+
20+
@@ -236,6 +228,21 @@ typedef struct {
21+
22+
typedef SearchResults *SearchResultsPtr;
23+
24+
+/* Make all the functions compatible with c++ files */
25+
+#ifdef __cplusplus
26+
+extern "C" {
27+
+#endif
28+
+
29+
+extern char* wnrelease; /* WordNet release/version number */
30+
+
31+
+extern char* lexfiles[]; /* names of lexicographer files */
32+
+extern char* ptrtyp[]; /* pointer characters */
33+
+extern char* partnames[]; /* POS strings */
34+
+extern char partchars[]; /* single chars for each POS */
35+
+extern char* adjclass[]; /* adjective class strings */
36+
+extern char* frametext[]; /* text of verb frames */
37+
+
38+
+
39+
/* Global variables and flags */
40+
41+
extern SearchResults wnresults; /* structure containing results of search */
42+
@@ -271,11 +278,6 @@ extern int default_display_message(char *);
43+
extern int (*display_message)(char *);
44+
45+
46+
-/* Make all the functions compatible with c++ files */
47+
-#ifdef __cplusplus
48+
-extern "C" {
49+
-#endif
50+
-
51+
/* External library function prototypes */
52+
53+
/*** Search and database functions (search.c) ***/
54+
diff --git a/lib/search.c b/lib/search.c
55+
index 1cdedc3..72c4bb5 100644
56+
--- a/lib/search.c
57+
+++ b/lib/search.c
58+
@@ -1256,7 +1256,7 @@ static void add_relatives(int pos, IndexPtr idx, int rel1, int rel2)
59+
{
60+
int i;
61+
struct relgrp *rel, *last, *r;
62+
-
63+
+ last = NULL;
64+
/* If either of the new relatives are already in a relative group,
65+
then add the other to the existing group (transitivity).
66+
Otherwise create a new group and add these 2 senses to it. */
67+
@@ -1281,8 +1281,9 @@ static void add_relatives(int pos, IndexPtr idx, int rel1, int rel2)
68+
rel->senses[rel1] = rel->senses[rel2] = 1;
69+
if (rellist == NULL)
70+
rellist = rel;
71+
- else
72+
- last->next = rel;
73+
+ else if (last) {
74+
+ last->next = rel;
75+
+ }
76+
}
77+
78+
static struct relgrp *mkrellist(void)

ports/wordnet/portfile.cmake

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
include(vcpkg_common_functions)
2+
3+
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
4+
5+
set(VERSION 3.0)
6+
7+
vcpkg_download_distfile(ARCHIVE
8+
URLS "http://wordnetcode.princeton.edu/${VERSION}/WordNet-${VERSION}.tar.gz"
9+
FILENAME "wordnet-${VERSION}.tar.gz"
10+
SHA512 9539bc016d710f31d65072bbf5068edffcd735978d8cc6f1b361b19428b97546ef6c7e246e1b6f2ff4557a0885a8305341e35173a6723f0740dda18d097ca248
11+
)
12+
13+
vcpkg_extract_source_archive_ex(
14+
OUT_SOURCE_PATH SOURCE_PATH
15+
ARCHIVE ${ARCHIVE}
16+
REF ${VERSION}
17+
PATCHES
18+
fix_gobal_vars_uninit_local_ptr.patch
19+
)
20+
21+
file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
22+
file(COPY ${CMAKE_CURRENT_LIST_DIR}/wordnet-config.cmake.in DESTINATION ${SOURCE_PATH})
23+
24+
if("dbfiles" IN_LIST FEATURES)
25+
vcpkg_download_distfile(WORDNET_DICT_DBFILES
26+
URLS "http://wordnetcode.princeton.edu/wn3.1.dict.tar.gz"
27+
FILENAME "wordnet-cache/wn3.1.dict.tar.gz"
28+
SHA512 16dca17a87026d8a0b7b4758219cd21a869c3ef3da23ce7875924546f2eacac4c2f376cb271b798b2c458fe8c078fb43d681356e3d9beef40f4bd88d3579394f
29+
)
30+
file(REMOVE_RECURSE "${SOURCE_PATH}/dict/")
31+
vcpkg_extract_source_archive_ex(
32+
OUT_SOURCE_PATH WORDNET_DICT_DBFILES_EX
33+
ARCHIVE ${WORDNET_DICT_DBFILES}
34+
REF 3.1
35+
WORKING_DIRECTORY ${SOURCE_PATH}
36+
)
37+
file(RENAME ${WORDNET_DICT_DBFILES_EX} "${SOURCE_PATH}/dict")
38+
endif()
39+
40+
set (WORDNET_DICT_PATH "${CURRENT_PACKAGES_DIR}/tools/${PORT}/dict")
41+
42+
vcpkg_configure_cmake(
43+
SOURCE_PATH ${SOURCE_PATH}
44+
PREFER_NINJA
45+
OPTIONS -DWORDNET_DICT_PATH=${WORDNET_DICT_PATH}
46+
)
47+
48+
vcpkg_install_cmake()
49+
vcpkg_copy_pdbs()
50+
vcpkg_fixup_cmake_targets()
51+
52+
# Handle copyright
53+
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/wordnet RENAME copyright)
54+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Config file for the wordnet package
2+
3+
get_filename_component(_WORDNET_PREFIX_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
4+
5+
set (_TARGET_NAME "wordnet")
6+
7+
set (WORDNET_DICT_PATH @WORDNET_DICT_PATH@)
8+
message (STATUS "WORDNET_DICT_PATH: @WORDNET_DICT_PATH@")
9+
10+
# IMPORTED targets for wordnet
11+
include("${_WORDNET_PREFIX_DIR}/${_TARGET_NAME}-targets.cmake")
12+
13+
set(_WORDNET_PREFIX_DIR)
14+
set(_TARGET_NAME)

0 commit comments

Comments
 (0)