<> <> <> <> <> <> <<>> DIRECTORY Basics USING [], CHNameP2V0 USING [], Convert USING [RopeFromAtom, AtomFromRope], CrRPC USING [CreateClientHandle, DestroyClientHandle, Error, Handle], Dictionary, DictionaryP1313V1, Rope, UserProfile USING [Token], XNS, XNSCH USING [LookupAddressFromRope], XNSCHName USING [Name]; DictionaryClientImpl: CEDAR MONITOR IMPORTS Convert, CrRPC, DictionaryP1313V1, UserProfile, XNSCH EXPORTS Dictionary ~ { OPEN Dictionary1: DictionaryP1313V1, Dictionary; ROPE: TYPE ~ Rope.ROPE; <> ExternalSynonymSeqHandle: TYPE ~ REF ExternalSynonymSeqObject; ExternalSynonymSeqObject: PUBLIC TYPE ~ RECORD [ handle: Dictionary1.SynonymClasses ]; <> Error: PUBLIC ERROR [problem: Problem, explanation: ROPE] ~ CODE; dictServer: PUBLIC ROPE ¬ UserProfile.Token["Dictionary.Server", "DictServer:PARC:Xerox"]; CrHandleFromRope: INTERNAL PROC [pattern: ROPE] RETURNS [h: CrRPC.Handle, name: XNSCHName.Name] ~ { transport: ATOM ~ IF ( BYTES[CARDINAL] = 2 ) THEN $SPP ELSE $CMUX; addr: XNS.Address; [name, addr] ¬ XNSCH.LookupAddressFromRope[pattern]; IF ( addr = XNS.unknownAddress ) THEN ERROR Error[courier, "Address not found"]; h ¬ CrRPC.CreateClientHandle[transport, NEW[XNS.Address ¬ addr]]; }; CourierProc: TYPE ~ PROC [h: CrRPC.Handle]; Guarded: ENTRY PROC [proc: CourierProc] ~ { ENABLE { UNWIND => { NULL }; Dictionary1.UseCourier, CrRPC.Error => { ERROR Error[courier, NIL] }; Dictionary1.RemoteError => { ERROR Error[service, string]; }; }; distingName: XNSCHName.Name; h: CrRPC.Handle ¬ NIL; [h, distingName] ¬ CrHandleFromRope[dictServer]; proc[h]; CrRPC.DestroyClientHandle[h]; }; <> DictionariesAvailableFor: PROC [seq: Dictionary1.DictionariesAvailable] RETURNS [list: DictionariesList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO rope: ROPE ~ seq.body[i]; item: ATOM ~ Convert.AtomFromRope[rope]; list ¬ CONS[item, list]; ENDLOOP; }; LanguagesFor: PROC [seq: Dictionary1.Languages] RETURNS [list: LanguagesList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO rope: ROPE ~ seq.body[i]; item: ATOM ~ Convert.AtomFromRope[rope]; list ¬ CONS[item, list]; ENDLOOP; }; Looks2For: PROC [seq: Dictionary1.Looks2] RETURNS [list: Looks2List] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO rope: ROPE ~ seq.body[i]; item: ATOM ~ Convert.AtomFromRope[rope]; list ¬ CONS[item, list]; ENDLOOP; }; <> WordsFor: PROC [seq: Dictionary1.Words] RETURNS [list: WordsList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO item: ROPE ~ seq.body[i]; list ¬ CONS[item, list]; ENDLOOP; }; SynonymClassFor: PROC [seq: Dictionary1.SynonymClass] RETURNS [list: SynonymClassList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO item: ROPE ~ seq.body[i]; list ¬ CONS[item, list]; ENDLOOP; }; <> IntegersFor: PROC [seq: Dictionary1.Integers] RETURNS [list: IntegersList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO item: INT32 ~ seq.body[i]; list ¬ CONS[item, list]; ENDLOOP; }; <> ConjugationsFor: PROC [seq: Dictionary1.Conjugations] RETURNS [list: ConjugationsList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO conj: Dictionary1.Conjugation ~ seq.body[i]; partOfSpeech: ATOM ~ Convert.AtomFromRope[conj.partsOfSpeech]; status: ATOM ~ Convert.AtomFromRope[conj.status]; item: ConjugationPointer ~ NEW[ExternalConjugationObject ¬ [partOfSpeech: partOfSpeech, definition: conj.definition, status: status] ]; list ¬ CONS[item, list]; ENDLOOP; }; RunsFor: PROC [seq: Dictionary1.Runs] RETURNS [list: RunList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO run: Dictionary1.Run ~ seq.body[i]; font: ATOM ~ Convert.AtomFromRope[run.font]; item: RunPointer ~ NEW[ExternalRunObject ¬ [start: run.start, length: run.length, font: font] ]; list ¬ CONS[item, list]; ENDLOOP; }; LooksFor: PROC [seq: Dictionary1.Looks] RETURNS [list: LooksList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO looks2: Dictionary1.Looks2 ~ seq.body[i]; item: Looks2List ~ Looks2For[looks2]; list ¬ CONS[item, list]; ENDLOOP; }; RawDefinitionFor: PROC [seq: Dictionary1.RawDefinition] RETURNS [list: RawDefinitionList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO comp: Dictionary1.Component ~ seq.body[i]; type: ATOM ~ Convert.AtomFromRope[comp.type]; defaultFont: ATOM ~ Convert.AtomFromRope[comp.defaultFont]; runList: RunList ~ RunsFor[comp.runs]; item: ComponentPointer ~ NEW[ExternalComponentObject ¬ [type: type, text: comp.text, defaultFont: defaultFont, runs: runList] ]; list ¬ CONS[item, list]; ENDLOOP; }; SynonymClassesFor: PROC [seq: Dictionary1.SynonymClasses] RETURNS [list: SynonymClassesList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO class: Dictionary1.SynonymClass ~ seq.body[i]; item: SynonymClassList ~ SynonymClassFor[class]; list ¬ CONS[item, list]; ENDLOOP; }; IntersectionResultsFor: PROC [seq: Dictionary1.IntersectionResults] RETURNS [list: IntersectionResultsList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO result: Dictionary1.IntersectionResult ~ seq.body[i]; keysList: WordsList ~ WordsFor[result.keys]; resultsList: WordsList ~ WordsFor[result.results]; item: IntersectionResultsPointer ~ NEW[ExternalIntersectionResultsObject ¬ [keys: keysList, results: resultsList] ]; list ¬ CONS[item, list]; ENDLOOP; }; RawIntersectionResultsFor: PROC [seq: Dictionary1.RawIntersectionResults] RETURNS [list: RawIntersectionResultsList] ~ { FOR i: CARDINAL DECREASING IN [0..seq.length) DO result: Dictionary1.RawIntersectionResult ~ seq.body[i]; keysList: WordsList ~ WordsFor[result.keys]; resultsList: IntegersList ~ IntegersFor[result.results]; item: RawIntersectionResultsPointer ~ NEW[ExternalRawIntersectionResultsObject ¬ [keys: keysList, results: resultsList] ]; list ¬ CONS[item, list]; ENDLOOP; }; <> <> <<>> SequenceToList: PROC [sequence: REF] RETURNS [any: REF] ~ { WITH sequence SELECT FROM conjugationSeq: Dictionary1.Conjugations => { conjugationsList: ConjugationsList ~ ConjugationsFor[conjugationSeq]; any ¬ NEW[ConjugationsList ¬ conjugationsList]; }; dictionariesSeq: Dictionary1.DictionariesAvailable => { dictionariesList: DictionariesList ~ DictionariesAvailableFor[dictionariesSeq]; any ¬ NEW[DictionariesList ¬ dictionariesList]; }; integersSeq: Dictionary1.Integers => { integersList: IntegersList ~ IntegersFor[integersSeq]; any ¬ NEW[IntegersList ¬ integersList]; }; intersectionResultsSeq: Dictionary1.IntersectionResults => { intersectionResultsList: IntersectionResultsList ~ IntersectionResultsFor[intersectionResultsSeq]; any ¬ NEW[IntersectionResultsList ¬ intersectionResultsList]; }; languagesSeq: Dictionary1.Languages => { languagesList: LanguagesList ~ LanguagesFor[languagesSeq]; any ¬ NEW[LanguagesList ¬ languagesList]; }; looks2Seq: Dictionary1.Looks2 => { looks2List: Looks2List ~ Looks2For[looks2Seq]; any ¬ NEW[Looks2List ¬ looks2List]; }; looksSeq: Dictionary1.Looks => { looksList: LooksList ~ LooksFor[looksSeq]; any ¬ NEW[LooksList ¬ looksList]; }; rawDefinitionSeq: Dictionary1.RawDefinition => { rawDefinitionList: RawDefinitionList ~ RawDefinitionFor[rawDefinitionSeq]; any ¬ NEW[RawDefinitionList ¬ rawDefinitionList]; }; rawIntersectionResultsSeq: Dictionary1.RawIntersectionResults => { rawIntersectionResultsList: RawIntersectionResultsList ~ RawIntersectionResultsFor[rawIntersectionResultsSeq]; any ¬ NEW[RawIntersectionResultsList ¬ rawIntersectionResultsList]; }; runSeq: Dictionary1.Runs => { runList: RunList ~ RunsFor[runSeq]; any ¬ NEW[RunList ¬ runList]; }; synonymClassesSeq: Dictionary1.SynonymClasses => { synonymClassesList: SynonymClassesList ~ SynonymClassesFor[synonymClassesSeq]; any ¬ NEW[SynonymClassesList ¬ synonymClassesList]; }; synonymClassSeq: Dictionary1.SynonymClass => { synonymClassList: SynonymClassList ~ SynonymClassFor[synonymClassSeq]; any ¬ NEW[SynonymClassList ¬ synonymClassList]; }; wordsSeq: Dictionary1.Words => { wordsList: WordsList ~ WordsFor[wordsSeq]; any ¬ NEW[WordsList ¬ wordsList]; }; ENDCASE => { NULL }; }; <> Languages: PUBLIC PROC [user: ROPE] RETURNS [languages: LanguagesList] = { xx: Dictionary1.Languages; LanguagesOp: CourierProc ~ { xx ¬ Dictionary1.GetLanguages[h, user]; }; Guarded[LanguagesOp]; languages ¬ LanguagesFor[xx]; }; Analyze: PUBLIC PROC [word: Word, language: Language] RETURNS [analyses: ROPE] = { lrope: ROPE ~ Convert.RopeFromAtom[language, FALSE]; AnalyzeOp: CourierProc ~ { analyses ¬ Dictionary1.Analyze[h, word, lrope]; }; Guarded[AnalyzeOp]; }; Translate: PUBLIC PROC [wordNumber: WordNumber, language: Language] RETURNS [word: Word] = { lrope: ROPE ~ Convert.RopeFromAtom[language, FALSE]; TranslateOp: CourierProc ~ { word ¬ Dictionary1.ConvertWordNumber[h, wordNumber, lrope]; }; Guarded[TranslateOp]; }; ProofRead: PUBLIC PROC [paragraph: Paragraph, language: Language] RETURNS [wordPosition: WordPosition] = { lrope: ROPE ~ Convert.RopeFromAtom[language, FALSE]; temp: Dictionary1.Selection ¬ [0, 0]; ProofReadOp: CourierProc ~ { temp ¬ Dictionary1.ProofRead[h, paragraph, lrope]; }; Guarded[ProofReadOp]; wordPosition ¬ NEW[ExternalWordPositionObject ¬ [temp.start, temp.length] ]; }; Corrections: PUBLIC PROC [word: Word, language: Language] RETURNS [wordsList: WordsList] = { lrope: ROPE ~ Convert.RopeFromAtom[language, FALSE]; xx: Dictionary1.Words; CorrectionsOp: CourierProc ~ { xx ¬ Dictionary1.Corrections[h, word, lrope]; }; Guarded[CorrectionsOp]; wordsList ¬ WordsFor[xx]; }; Status: PUBLIC PROC RETURNS [statusInfo: ROPE] = { StatusOp: CourierProc ~ { statusInfo ¬ Dictionary1.Status[h]; }; Guarded[StatusOp]; }; CountWords: PUBLIC PROC [paragraph: Paragraph, language: Language] RETURNS [wordCount: INT32 ¬ 0] = { lrope: ROPE ~ Convert.RopeFromAtom[language, FALSE]; CountWordsOp: CourierProc ~ { wordCount ¬ Dictionary1.CountWords[h, paragraph, lrope]; }; Guarded[CountWordsOp]; }; Conjugate: PUBLIC PROC [word: Word, form: Form, alternates: Alternates, language: Language] RETURNS [conjugationsList: ConjugationsList] = { frope: ROPE ~ Convert.RopeFromAtom[form, FALSE]; arope: ROPE ~ Convert.RopeFromAtom[alternates, FALSE]; lrope: ROPE ~ Convert.RopeFromAtom[language, FALSE]; xx: Dictionary1.Conjugations; ConjugateOp: CourierProc ~ { xx ¬ Dictionary1.Conjugate[h, word, frope, arope, lrope]; }; Guarded[ConjugateOp]; conjugationsList ¬ ConjugationsFor[xx]; }; Dictionaries: PUBLIC PROC [user: User] RETURNS [dictionariesList: DictionariesList] = { xx: Dictionary1.DictionariesAvailable; DictionariesOp: CourierProc ~ { xx ¬ Dictionary1.Dictionaries[h, user]; }; Guarded[DictionariesOp]; dictionariesList ¬ DictionariesAvailableFor[xx]; }; GetDefinition: PUBLIC PROC [word: Word, dictionary: Dictionary] RETURNS [definition: Definition] = { drope: ROPE ~ Convert.RopeFromAtom[dictionary, FALSE]; temp: Dictionary1.Definition; runs: RunList; GetDefinitionOp: CourierProc ~ { temp ¬ Dictionary1.GetDefinition[h, word, drope]; }; Guarded[GetDefinitionOp]; runs ¬ RunsFor[temp.runs]; definition ¬ NEW[ExternalDefinitionObject ¬ [definition: temp.definition, looks: runs] ]; }; Pronunciation: PUBLIC PROC [word: Word, dictionary: Dictionary] RETURNS [wordPronounced: ROPE] = { drope: ROPE ~ Convert.RopeFromAtom[dictionary, FALSE]; PronunciationOp: CourierProc ~ { wordPronounced ¬ Dictionary1.Pronunciation[h, word, drope]; }; Guarded[PronunciationOp]; }; GetLooks: PUBLIC PROC [dictionary: Dictionary] RETURNS [looksList: LooksList] = { drope: ROPE ~ Convert.RopeFromAtom[dictionary, FALSE]; xx: Dictionary1.Looks; GetLooksOp: CourierProc ~ { xx ¬ Dictionary1.GetLooks[h, drope]; }; Guarded[GetLooksOp]; looksList ¬ LooksFor[xx]; }; Enumerate: PUBLIC PROC [wordNumber: WordNumber, dictionary: Dictionary] RETURNS [definition: Definition] = { drope: ROPE ~ Convert.RopeFromAtom[dictionary, FALSE]; temp: Dictionary1.Definition; runs: RunList; EnumerateOp: CourierProc ~ { temp ¬ Dictionary1.Enumerate[h, wordNumber, drope]; }; Guarded[EnumerateOp]; runs ¬ RunsFor[temp.runs]; definition ¬ NEW[ExternalDefinitionObject ¬ [definition: temp.definition, looks: runs] ]; }; ConvertCodes: PROC [codes: CodesList] RETURNS [seq: Dictionary1.Codes] ~ { length: CARDINAL ¬ 0; FOR tail: CodesList ¬ codes, tail.rest WHILE ( tail # NIL ) DO length ¬ length.SUCC; ENDLOOP; <> seq ¬ NEW[Dictionary1.CodesObject[length]]; FOR i: CARDINAL IN [0..length) DO rope: ROPE ~ Convert.RopeFromAtom[codes.first]; seq[i] ¬ rope; codes ¬ codes.rest; ENDLOOP; }; EnumerateRaw: PUBLIC PROC [wordNumber: WordNumber, codes: CodesList, dictionary: Dictionary] RETURNS [rawDefinitionList: RawDefinitionList] = { drope: ROPE ~ Convert.RopeFromAtom[dictionary, FALSE]; seq: Dictionary1.Codes ~ ConvertCodes[codes]; xx: Dictionary1.RawDefinition; EnumerateRawOp: CourierProc ~ { xx ¬ Dictionary1.EnumerateRaw[h, wordNumber, seq, drope]; }; Guarded[EnumerateRawOp]; rawDefinitionList ¬ RawDefinitionFor[xx]; }; SearchForWord: PUBLIC PROC [unparsedClasses: UnparsedClasses, minKeyWords: MinKeyWords, minWord: MinWord, maxWord: MaxWord, dictionary: Dictionary] RETURNS [intersectionResultsList: IntersectionResultsList] = { drope: ROPE ~ Convert.RopeFromAtom[dictionary, FALSE]; xx: Dictionary1.IntersectionResults; trans: REF; SearchForWordOp: CourierProc ~ { xx ¬ Dictionary1.SearchForWord[h, unparsedClasses, minKeyWords, minWord, maxWord, drope]; }; Guarded[SearchForWordOp]; intersectionResultsList ¬ IntersectionResultsFor[xx]; }; Synonyms: PUBLIC PROC [word: Word, dictionary: Dictionary] RETURNS [externalSynonymHandle: ExternalSynonymHandle] = { drope: ROPE ~ Convert.RopeFromAtom[dictionary, FALSE]; internal: Dictionary1.SynonymClasses; external: ExternalSynonymSeqHandle; classes: SynonymClassesList; SynonymsOp: CourierProc ~ { internal ¬ Dictionary1.Synonyms[h, word, drope]; }; Guarded[SynonymsOp]; external ¬ NEW[ExternalSynonymSeqObject ¬ [handle: internal] ]; classes ¬ SynonymClassesFor[internal]; externalSynonymHandle ¬ NEW[ExternalSynonymObject ¬ [synonymList: classes, externalSynonymSeqHandle: external] ]; }; NewSearchForWord: PUBLIC PROC [externalSynonymHandle: ExternalSynonymHandle, minKeyWords: MinKeyWords, minWord: MinWord, maxWord: MaxWord, dictionary: Dictionary] RETURNS [intersectionResultsList: IntersectionResultsList] = { drope: ROPE ~ Convert.RopeFromAtom[dictionary, FALSE]; classes: Dictionary1.SynonymClasses ~ externalSynonymHandle.externalSynonymSeqHandle.handle; xx: Dictionary1.IntersectionResults; trans: REF; NewSearchForWordOp: CourierProc ~ { xx ¬ Dictionary1.NewSearchForWord[h, classes, minKeyWords, minWord, maxWord, drope]; }; Guarded[NewSearchForWordOp]; intersectionResultsList ¬ IntersectionResultsFor[xx]; }; RawSearchForWord: PUBLIC PROC [externalSynonymHandle: ExternalSynonymHandle, minKeyWords: MinKeyWords, minWord: MinWord, maxWord: MaxWord, dictionary: Dictionary] RETURNS [rawIntersectionResultsList: RawIntersectionResultsList] = { drope: ROPE ~ Convert.RopeFromAtom[dictionary, FALSE]; classes: Dictionary1.SynonymClasses ~ externalSynonymHandle.externalSynonymSeqHandle.handle; xx: Dictionary1.RawIntersectionResults; trans: REF; RawSearchForWordOp: CourierProc ~ { xx ¬ Dictionary1.RawSearchForWord[h, classes, minKeyWords, minWord, maxWord, drope]; }; Guarded[RawSearchForWordOp]; rawIntersectionResultsList ¬ RawIntersectionResultsFor[xx]; }; }.