Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/NSLinguisticTagger test
Function:
Required plugins for this example: MBS MacFrameworks Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/NSLinguisticTagger test
This example is the version from Mon, 11th Jun 2017.
Project "NSLinguisticTagger test.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control MyTextArea Inherits TextArea
ControlInstance MyTextArea Inherits TextArea
End Control
Control FindNamesButton Inherits PushButton
ControlInstance FindNamesButton Inherits PushButton
EventHandler Sub Action() dim TagScheme as string = NSLinguisticTaggerMBS.NSLinguisticTagSchemeNameType dim TagSchemes() as string = array(TagScheme) dim options as integer = NSLinguisticTaggerMBS.NSLinguisticTaggerJoinNames dim tagger as new NSLinguisticTaggerMBS(TagSchemes, options) dim t as string = MyTextArea.Text tagger.Text = t dim range as new NSRangeMBS(0, t.len) dim tags() as NSLinguisticValueMBS = tagger.tagsInRange(range, TagScheme, options) MyTextArea.TextColor = &c000000 List.DeleteAllRows for each tag as NSLinguisticValueMBS in tags dim tokenRange as NSRangeMBS = tag.tokenRange Select case tag.tag case NSLinguisticTaggerMBS.NSLinguisticTagPersonalName MyTextArea.SelStart = tokenRange.Location MyTextArea.SelLength = tokenRange.Length MyTextArea.SelTextColor = &c0000FF case NSLinguisticTaggerMBS.NSLinguisticTagOrganizationName MyTextArea.SelStart = tokenRange.Location MyTextArea.SelLength = tokenRange.Length MyTextArea.SelTextColor = &c0088FF case NSLinguisticTaggerMBS.NSLinguisticTagPlaceName MyTextArea.SelStart = tokenRange.Location MyTextArea.SelLength = tokenRange.Length MyTextArea.SelTextColor = &cFF8800 end Select List.AddRow tokenRange.String, tag.Text, tag.Tag next MyTextArea.SelStart = 0 MyTextArea.SelLength = 0 End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control FindNamesButton1 Inherits PushButton
ControlInstance FindNamesButton1 Inherits PushButton
EventHandler Sub Action() dim TagScheme as string = NSLinguisticTaggerMBS.NSLinguisticTagSchemeLexicalClass dim TagSchemes() as string = array(TagScheme) dim options as integer = 0 dim tagger as new NSLinguisticTaggerMBS(TagSchemes, options) dim t as string = MyTextArea.Text tagger.Text = t dim range as new NSRangeMBS(0, t.len) dim tags() as NSLinguisticValueMBS = tagger.tagsInRange(range, TagScheme, options) MyTextArea.TextColor = &c000000 List.DeleteAllRows for each tag as NSLinguisticValueMBS in tags dim tokenRange as NSRangeMBS = tag.tokenRange Select case tag.tag case NSLinguisticTaggerMBS.NSLinguisticTagVerb MyTextArea.SelStart = tokenRange.Location MyTextArea.SelLength = tokenRange.Length MyTextArea.SelTextColor = &c0000FF case NSLinguisticTaggerMBS.NSLinguisticTagNoun MyTextArea.SelStart = tokenRange.Location MyTextArea.SelLength = tokenRange.Length MyTextArea.SelTextColor = &c880000 end Select List.AddRow tokenRange.String, tag.Text, tag.Tag next MyTextArea.SelStart = 0 MyTextArea.SelLength = 0 End EventHandler
End Control
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacFrameworks Plugin.





Links
MBS Xojo Plugins