<> <> <> <> <> <<>> 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; 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] = { 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; 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]; }; }.