Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,71 +0,0 @@
|
|||
with Ada.Containers.Indefinite_Vectors;
|
||||
with Ada.Strings.Fixed;
|
||||
with Ada.Strings.Maps;
|
||||
with Ada.Text_IO;
|
||||
|
||||
procedure Abbreviations is
|
||||
|
||||
package String_Vectors is
|
||||
new Ada.Containers.Indefinite_Vectors (Index_Type => Positive,
|
||||
Element_Type => String);
|
||||
use Ada.Text_IO, String_Vectors;
|
||||
|
||||
function Split (Line : String) return Vector is
|
||||
Result : Vector;
|
||||
First : Natural;
|
||||
Last : Natural := Line'First - 1;
|
||||
begin
|
||||
while Last + 1 in Line'Range loop
|
||||
Ada.Strings.Fixed.Find_Token
|
||||
(Line, Ada.Strings.Maps.To_Set (" "), Last + 1,
|
||||
Ada.Strings.Outside, First, Last);
|
||||
exit when Last = 0;
|
||||
Append (Result, Line (First .. Last));
|
||||
end loop;
|
||||
return Result;
|
||||
end Split;
|
||||
|
||||
function Abbrev_Length (Items : Vector) return Natural is
|
||||
use type Ada.Containers.Count_Type;
|
||||
Max : Natural := 0;
|
||||
Abbrevs : Vector;
|
||||
begin
|
||||
for Item of Items loop
|
||||
Max := Natural'Max (Max, Item'Length);
|
||||
end loop;
|
||||
|
||||
for Length in 1 .. Max loop
|
||||
Abbrevs := Empty_Vector;
|
||||
for Item of Items loop
|
||||
declare
|
||||
Last : constant Natural
|
||||
:= Natural'Min (Item'Last, Item'First + Length - 1);
|
||||
|
||||
Abbrev : String renames Item (Item'First .. Last);
|
||||
begin
|
||||
exit when Abbrevs.Contains (Abbrev);
|
||||
Abbrevs.Append (Abbrev);
|
||||
end;
|
||||
end loop;
|
||||
if Abbrevs.Length = Items.Length then
|
||||
return Length;
|
||||
end if;
|
||||
end loop;
|
||||
return 0;
|
||||
end Abbrev_Length;
|
||||
|
||||
procedure Process (Line : String) is
|
||||
package Natural_IO is new Ada.Text_IO.Integer_IO (Natural);
|
||||
Words : constant Vector := Split (Line);
|
||||
Length : constant Natural := Abbrev_Length (Words);
|
||||
begin
|
||||
Natural_IO.Put (Length, Width => 2);
|
||||
Put (" ");
|
||||
Put_Line (Line);
|
||||
end Process;
|
||||
|
||||
begin
|
||||
while not End_Of_File loop
|
||||
Process (Get_Line);
|
||||
end loop;
|
||||
end Abbreviations;
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. AUTO-ABBREVIATIONS.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT DOW ASSIGN TO "days-of-week.txt"
|
||||
ORGANIZATION IS LINE SEQUENTIAL.
|
||||
|
||||
DATA DIVISION.
|
||||
FILE SECTION.
|
||||
FD DOW.
|
||||
01 DOW-FILE PIC X(200).
|
||||
|
||||
WORKING-STORAGE SECTION. *> a.k.a. variables
|
||||
01 DOW-LINE PIC X(200).
|
||||
01 ENDO PIC 9(1).
|
||||
01 ENDO2 PIC 9(1).
|
||||
01 CURDAY PIC X(50).
|
||||
01 ABPTR PIC 999.
|
||||
01 LINE-NUM PIC 9(3) VALUE 1.
|
||||
01 CHARAMT PIC 9(3) VALUE 1.
|
||||
01 LARGESTCHARAMT PIC 9(3).
|
||||
01 DAYNUM PIC 9(3) VALUE 1.
|
||||
01 ABRESTART PIC 9(1).
|
||||
01 CURABBR PIC X(50).
|
||||
01 TMP1 PIC 9(3).
|
||||
01 TMP2 PIC 9(3).
|
||||
01 TINDEX PIC 9(3) VALUE 1.
|
||||
01 ABBRLIST.
|
||||
05 ABBRITEM PIC X(50) OCCURS 7 TIMES.
|
||||
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
OPEN INPUT DOW.
|
||||
PERFORM UNTIL ENDO = 1
|
||||
READ DOW INTO DOW-LINE
|
||||
AT END MOVE 1 TO ENDO
|
||||
NOT AT END PERFORM
|
||||
*> loop through each line
|
||||
IF DOW-LINE = "" THEN
|
||||
DISPLAY ""
|
||||
ELSE
|
||||
MOVE 0 TO ENDO2
|
||||
MOVE 0 TO CHARAMT
|
||||
|
||||
PERFORM UNTIL ENDO2 > 0
|
||||
MOVE 1 TO ABPTR
|
||||
MOVE 1 TO DAYNUM
|
||||
MOVE 0 TO ABRESTART
|
||||
|
||||
ADD 1 TO CHARAMT
|
||||
|
||||
*> reset the abbreviation table
|
||||
MOVE 1 TO TINDEX
|
||||
PERFORM 7 TIMES
|
||||
MOVE SPACE TO ABBRITEM(TINDEX)
|
||||
ADD 1 TO TINDEX
|
||||
END-PERFORM
|
||||
|
||||
*> loop through each day
|
||||
PERFORM 7 TIMES
|
||||
UNSTRING DOW-LINE DELIMITED BY SPACE
|
||||
INTO CURDAY
|
||||
WITH POINTER ABPTR
|
||||
END-UNSTRING
|
||||
|
||||
MOVE 0 TO TMP1
|
||||
MOVE 0 TO TMP2
|
||||
INSPECT CURDAY
|
||||
TALLYING TMP1 FOR ALL CHARACTERS
|
||||
INSPECT CURDAY
|
||||
TALLYING TMP2 FOR ALL SPACE
|
||||
SUBTRACT TMP2 FROM TMP1
|
||||
IF TMP1 > LARGESTCHARAMT THEN
|
||||
MOVE TMP1 TO LARGESTCHARAMT
|
||||
END-IF
|
||||
|
||||
*> not enough days error
|
||||
IF CURDAY = "" THEN
|
||||
MOVE 3 TO ENDO2
|
||||
END-IF
|
||||
|
||||
MOVE CURDAY(1:CHARAMT) TO CURABBR
|
||||
|
||||
*> check if the current abbreviation is already taken
|
||||
MOVE 1 TO TINDEX
|
||||
PERFORM 7 TIMES
|
||||
IF ABBRITEM(TINDEX) = CURABBR THEN
|
||||
MOVE 1 TO ABRESTART
|
||||
END-IF
|
||||
ADD 1 TO TINDEX
|
||||
END-PERFORM
|
||||
|
||||
MOVE CURABBR TO ABBRITEM(DAYNUM)
|
||||
|
||||
ADD 1 TO DAYNUM
|
||||
|
||||
END-PERFORM
|
||||
|
||||
IF ABRESTART = 0 THEN
|
||||
MOVE 1 TO ENDO2
|
||||
END-IF
|
||||
|
||||
*> identical days error
|
||||
IF CHARAMT > LARGESTCHARAMT THEN
|
||||
MOVE 2 TO ENDO2
|
||||
END-IF
|
||||
|
||||
END-PERFORM
|
||||
|
||||
DISPLAY "Line " LINE-NUM ": " WITH NO ADVANCING
|
||||
|
||||
IF ENDO2 = 3 THEN
|
||||
DISPLAY "Error: not enough " WITH NO ADVANCING
|
||||
DISPLAY "days"
|
||||
ELSE IF ENDO2 = 2 THEN
|
||||
DISPLAY "Error: identical " WITH NO ADVANCING
|
||||
DISPLAY "days"
|
||||
ELSE
|
||||
DISPLAY CHARAMT ": " WITH NO ADVANCING
|
||||
|
||||
*> loop through each day and display its abbreviation
|
||||
MOVE 1 TO TINDEX
|
||||
PERFORM 7 TIMES
|
||||
MOVE ABBRITEM(TINDEX) TO CURABBR
|
||||
|
||||
MOVE 0 TO TMP1
|
||||
MOVE 0 TO TMP2
|
||||
INSPECT CURABBR
|
||||
TALLYING TMP1 FOR ALL CHARACTERS
|
||||
INSPECT CURABBR
|
||||
TALLYING TMP2 FOR TRAILING SPACES
|
||||
SUBTRACT TMP2 FROM TMP1
|
||||
|
||||
DISPLAY CURABBR(1:TMP1) WITH NO ADVANCING
|
||||
DISPLAY "." WITH NO ADVANCING
|
||||
|
||||
IF TINDEX < 7 THEN
|
||||
DISPLAY SPACE WITH NO ADVANCING
|
||||
ELSE
|
||||
DISPLAY X"0a" WITH NO ADVANCING *> go to next line
|
||||
END-IF
|
||||
|
||||
ADD 1 TO TINDEX
|
||||
END-PERFORM
|
||||
END-IF
|
||||
|
||||
END-IF
|
||||
|
||||
END-PERFORM
|
||||
END-READ
|
||||
|
||||
ADD 1 TO LINE-NUM
|
||||
END-PERFORM.
|
||||
CLOSE DOW.
|
||||
STOP RUN.
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
(defun abbreviate-list (list-of-days abbreviation-length)
|
||||
"Take each element of LIST-OF-DAYS and abbreviate to ABBREVIATION-LENGTH."
|
||||
(let ((abbrev-list)
|
||||
(abbrev-element))
|
||||
(dolist (one-element list-of-days) ; loop through each day of week
|
||||
;; if the day of week is at least as long as the abbreviation
|
||||
(if (>= (length one-element) abbreviation-length) ; if day >= abbreviation length
|
||||
(setq abbrev-element (substring one-element 0 abbreviation-length)) ; abbreviate the day of the week
|
||||
(setq abbrev-element one-element)) ; otherwise don't abbreviate
|
||||
(push abbrev-element abbrev-list)) ; put the abbreviated/non-abbreviated day on our list
|
||||
abbrev-list)) ; return the list of abbreviated days
|
||||
|
||||
(defun cycle-days (list-of-days)
|
||||
"Find shortest unique abbreviation in LIST-OF-DAYS list."
|
||||
(let ((abbrev-list)
|
||||
(abbrev-length 1)
|
||||
(current-abbrev)
|
||||
(looking-for-shortest-list t))
|
||||
(if (= (length list-of-days) 0) ; if list-of-days is empty (i.e., blank line)
|
||||
(setq looking-for-shortest-list nil)) ; then don't look for the shortest unique abbreviations
|
||||
(while looking-for-shortest-list ; as long as we are looking for the shortest unique abbreviations
|
||||
(setq abbrev-list (abbreviate-list list-of-days abbrev-length)) ; get a list of abbreviated day names
|
||||
(if (= (length list-of-days) (length (seq-uniq abbrev-list))) ; if abbreviated list has no duplicates
|
||||
(progn
|
||||
(message (format "%d %s" abbrev-length list-of-days)) ; then in echo buffer show length and days
|
||||
(setq looking-for-shortest-list nil)) ; also, then don't look for the shortest unique abbreviations
|
||||
(setq abbrev-length (+ abbrev-length 1)))))) ; else increase the length of the abbreviation; loop to while
|
||||
|
||||
(defun days-of-week ()
|
||||
"Find minimum abbreviation length of days of week."
|
||||
(let ((current-line-list))
|
||||
(find-file "Days_of_week.txt") ; open file or switch to buffer
|
||||
(beginning-of-buffer) ; go to the top of the buffer
|
||||
(dolist (current-line (split-string (buffer-string) "\n")) ; go line by line through buffer
|
||||
(setq current-line-list (split-string current-line " ")) ; change each line into list of days of week
|
||||
(cycle-days current-line-list))))
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
sub print(s) wscript.stdout.writeline s :end sub
|
||||
|
||||
set d=createobject("Scripting.Dictionary")
|
||||
set fso=createobject("Scripting.Filesystemobject")
|
||||
|
||||
const fn="weekdays_ansi.txt"
|
||||
sfn=WScript.ScriptFullName
|
||||
sfn= Left(sfn, InStrRev(sfn, "\"))
|
||||
set f=fso.opentextfile(sfn & fn,1)
|
||||
|
||||
while not f.atendofstream
|
||||
s=f.readline
|
||||
if s=vbNullString then
|
||||
print " "
|
||||
else
|
||||
a=split(trim(s)," ")
|
||||
for abrlen=1 to 14
|
||||
d.removeall
|
||||
for wd=0 to 6
|
||||
k=left(a(wd),abrlen)
|
||||
if d.exists(k) then
|
||||
exit for
|
||||
else
|
||||
d.add k,""
|
||||
end if
|
||||
next 'wd
|
||||
if wd>6 then exit for
|
||||
next 'abrlen
|
||||
b=right(" " & abrlen,2)
|
||||
for wd=0 to 6
|
||||
b=b &" "& left(a(wd),abrlen)
|
||||
next
|
||||
print b
|
||||
end if
|
||||
wend 'line
|
||||
f.close
|
||||
Loading…
Add table
Add a link
Reference in a new issue