-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloader.pl
145 lines (124 loc) · 4.44 KB
/
loader.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/****************************************************************************
*
* PUBLIC DOMAIN NOTICE
* Lister Hill National Center for Biomedical Communications
* National Library of Medicine
* National Institues of Health
* United States Department of Health and Human Services
*
* This software is a United States Government Work under the terms of the
* United States Copyright Act. It was written as part of the authors'
* official duties as United States Government employees and contractors
* and thus cannot be copyrighted. This software is freely available
* to the public for use. The National Library of Medicine and the
* United States Government have not placed any restriction on its
* use or reproduction.
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the National Library of Medicine
* and the United States Government do not and cannot warrant the performance
* or results that may be obtained by using this software or data.
* The National Library of Medicine and the U.S. Government disclaim all
* warranties, expressed or implied, including warranties of performance,
* merchantability or fitness for any particular purpose.
*
* For full details, please see the MetaMap Terms & Conditions, available at
* https://metamap.nlm.nih.gov/MMTnCs.shtml.
*
***************************************************************************/
% File: loader.pl
% Module: MetaMap
% Author: Lan
% Purpose: Loads SKR for MetaMap
%
% Note that MetaMap is now subsumed by SKR.
% In particular, metamap_fe and metamap have been replaced by skr_fe and skr.
:- use_module(skr(skr_fe), [
fg/0,
go/0,
go/1,
go/2,
gt/0
]).
:- use_module(skr(skr), [
stop_skr/0
]).
:- use_module(skr_lib(nls_signal), [
establish_signal_handling/0
]).
:- use_module(skr_lib(sicstus_utils), [
ttyflush/0
]).
:- use_module(library(file_systems), [
file_exists/1,
file_property/3
]).
:- use_module(library(random), [
random/1,
setrand/1
]).
:- use_module(library(system), [
datime/1
]).
:- use_module(skr_lib(print_chars)).
:- prolog_flag(agc_margin, Current), New is 5*Current, prolog_flag(agc_margin, Current, New).
:- prolog_flag(gc_margin, Current), New is 5*Current, prolog_flag(gc_margin, Current, New).
%%% Code provided by Mats Carlsson of SICS to FML via e-mail 03/27/2007:
%%%
%%% There are two issues:
%%%
%%% 1. The initial seed of the random number generator is always the
%%% same. This is by design, so that you can reproduce the run with the
%%% same result, which is sometimes desirable. To get different
%%% sequences of random numbers each time, the seed has to be set
%%% explicitly.
%%%
%%% 2. There's a bug in maybe/[0,1] that makes it always fail the first
%%% time, no matter what the seed is.
%%%
%%% The piece of code below addresses both issues: it computes a random
%%% seed, and it calls maybe/0 once to compensate for the bug.
%%% --Mats
%%%
%%% SICStus version updated by Per Mildner.
:- initialization
datime(Date),
Date = datime(A,B,C,D,E,F),
X is 1 + ((A*D) mod 30000),
Y is 1 + ((B*E) mod 30000),
Z is 1 + ((C*F) mod 30000),
%% high bits matters so make W big
random(R),
W is 1 + integer(R*(1<<30)),
setrand(random(X,Y,Z,W)).
runtime_entry(start) :-
establish_signal_handling,
go.
runtime_entry(abort) :-
format(user_error,'~nDisconnecting servers and closing files...',[]),
ttyflush,
stop_skr,
format(user_error,'Done.~n',[]).
pl_to_po :-
source_file(FilePL),
compile_to_PO_if_necessary(FilePL),
fail
; true.
compile_to_PO_if_necessary(FilePL) :-
( sub_atom(FilePL, _, _, _, 'SKR') ->
true
; sub_atom(FilePL, _, _, _, public_mm)
),
atom_concat(Prefix, '.pl', FilePL),
atom_concat(Prefix, '.po', FilePO),
% UNLESS the PO file exists and is more recent than the PL file,
% compile the PL file to PO
( file_exists(FilePO),
file_property(FilePL, modify_timestamp, TimeStampPL),
file_property(FilePO, modify_timestamp, TimeStampPO),
TimeStampPO > TimeStampPL ->
true
; format(user_error, 'Saving ~w to ~w~n', [FilePL,FilePO]),
save_files(FilePL, FilePO)
).
:- pl_to_po.