Lisp HUG Maillist Archive

Objective C @interface

I'm trying to implement some natural language parsing features using Apple's API:

https://developer.apple.com/documentation/naturallanguage/nltokenizer?language=objc

NLTokenizer is an @interface, not a class - I'm not sure how to translate that into the LispWorks Objective-C API. Anyone have an example or something similar?

Thanks,

John DeSoi, Ph.D.


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Re: Objective C @interface



On 31 Jan 2019, at 21:01, John DeSoi <desoi@pgedit.com> wrote:

I'm trying to implement some natural language parsing features using Apple's API:

https://developer.apple.com/documentation/naturallanguage/nltokenizer?language=objc

NLTokenizer is an @interface, not a class - I'm not sure how to translate that into the LispWorks Objective-C API. Anyone have an example or something similar?

No, this is a class.  Interfaces are called @protocol in Objective-C.
The definition of an Objective-C  class is split out into one or more @interface sections and one or more @implementation sections.
The @interface sections specify the API of the class, and the @implementation section specify the implementation of the class.
When you want to define an interface that can be implemented by different (unrelated) class APIs, you use @protocol sections.

Translated to Lisp, @protocol (interfaces) have no formal correspondance. You could still use the Objective-C runtime to introspect defined @protocol, and check if a run-time class implements this @protocol.  But there would be no real constraints based on them.  It’s used by Objective-C compiler to provide compilation-time verifications.

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/DefiningClasses/DefiningClasses.html#//apple_ref/doc/uid/TP40011210-CH3-SW5

NLTokenizer is a class.


-- 
__Pascal J. Bourguignon__




Re: Objective C @interface

On Jan 31, 2019, at 4:51 PM, Pascal Bourguignon <pjb@informatimago.com> wrote:
> 
>> https://developer.apple.com/documentation/naturallanguage/nltokenizer?language=objc
>> 
>> NLTokenizer is an @interface, not a class - I'm not sure how to translate that into the LispWorks Objective-C API. Anyone have an example or something similar?
> 
> No, this is a class.  Interfaces are called @protocol in Objective-C.
> 

Well, the link above says "@interface NLTokenizer : NSObject". But if you switch the language option to Swift, it says it is a class. The only reference to @interface I found the LW documentation says:

> Note that the Lisp method definition form is separate from the class definition, unlike in Objective-C where it is embedded in the @implementation block. Also, there is no Lisp equivalent of the @interfaceblock: the methods of an Objective-C class are just those whose defining forms have been evaluated.

I could not find a single Objective C example online. The Swift example (https://developer.apple.com/documentation/naturallanguage/tokenizing_natural_language_text) shows:

let tokenizer = NLTokenizer(unit: .word)
tokenizer.string = text



I tried, for example:

 (invoke (invoke "NSObject" "alloc") "initWithUnit:" ".word")

Error: No method "initWithUnit:" for object #<Pointer: OBJC-OBJECT-POINTER = #x000060C000001FA0>, class "NSObject".
  1 (abort) Return to level 0.
  2 Return to top loop level 0.



Also,

(invoke (invoke "NLTokenizer" "alloc") "initWithUnit:" ".word")

Error: Cannot find class "NLTokenizer".
  1 (abort) Return to level 0.
  2 Return to top loop level 0.


John DeSoi, Ph.D.


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Re: Objective C @interface



On 1 Feb 2019, at 01:51, John DeSoi <desoi@pgedit.com> wrote:

On Jan 31, 2019, at 4:51 PM, Pascal Bourguignon <pjb@informatimago.com> wrote:

https://developer.apple.com/documentation/naturallanguage/nltokenizer?language=objc

NLTokenizer is an @interface, not a class - I'm not sure how to translate that into the LispWorks Objective-C API. Anyone have an example or something similar?

No, this is a class.  Interfaces are called @protocol in Objective-C.


Well, the link above says "@interface NLTokenizer : NSObject". But if you switch the language option to Swift, it says it is a class. The only reference to @interface I found the LW documentation says:

Note that the Lisp method definition form is separate from the class definition, unlike in Objective-C where it is embedded in the @implementation block. Also, there is no Lisp equivalent of the @interfaceblock: the methods of an Objective-C class are just those whose defining forms have been evaluated.

I could not find a single Objective C example online. The Swift example (https://developer.apple.com/documentation/naturallanguage/tokenizing_natural_language_text) shows:

let tokenizer = NLTokenizer(unit: .word)
tokenizer.string = text



I tried, for example:

(invoke (invoke "NSObject" "alloc") "initWithUnit:" ".word")

Error: No method "initWithUnit:" for object #<Pointer: OBJC-OBJECT-POINTER = #x000060C000001FA0>, class "NSObject”.

Yes, obviously.

Also,

(invoke (invoke "NLTokenizer" "alloc") "initWithUnit:" ".word")

Error: Cannot find class "NLTokenizer”.

https://developer.apple.com/documentation/naturallanguage/nltokenizer?language=objc
It’s in the Framework: Natural Language.
So you need to load this framework first.

Actually, it’s named NaturalLanguage:
$ ls -ld /System/Library/Frameworks/Natu*
drwxr-xr-x 5 root wheel 160 Oct 26 19:50 /System/Library/Frameworks/NaturalLanguage.framework/
 
So, I would do something like:

(when [[NSBunle bundleWithPath:@"/System/Library/Frameworks/NaturalLanguage.framework"] load]
  (let ((tokenizer [[NLTokenizer alloc] initWithUnit:@".word"]))

    [tokenizer …]
    
    ))

(since I would use my Objective-CL reader macros; you can translate it to invoke calls).

-- 
__Pascal J. Bourguignon__




Re: Objective C @interface

Thank you for the helpful hint. I have been away from this for around a decade, so it is taking a while for it to make sense again.

Unfortunately I discovered there is no such framework path in 10.13, but it is there in 10.14 Mojave. I'll have to upgrade before exploring this further.

John DeSoi, Ph.D.

 

> On Jan 31, 2019, at 7:34 PM, Pascal Bourguignon <pjb@informatimago.com> wrote:
> 
> So, I would do something like:
> 
> (when [[NSBunle bundleWithPath:@"/System/Library/Frameworks/NaturalLanguage.framework"] load]
>   (let ((tokenizer [[NLTokenizer alloc] initWithUnit:@".word"]))
> 
>     [tokenizer …]
>     
>     ))


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Updated at: 2020-12-10 08:29 UTC