[Foundation] Add missing NSLinguisticAnalysis category. Fixes 35009. (#3473)

* [Foundation] Add missing NSLinguisticAnalysis category. Fixes 35009.
This commit is contained in:
Manuel de la Pena 2018-02-16 16:21:47 +01:00 коммит произвёл GitHub
Родитель 4cd3f5c2d9
Коммит 688b3020f9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 235 добавлений и 5 удалений

Просмотреть файл

@ -125,4 +125,126 @@ namespace Foundation {
Interactive = 2,
Aggregate = 3,
}
public enum NSLinguisticTagScheme {
[Field ("NSLinguisticTagSchemeTokenType")]
Token,
[Field ("NSLinguisticTagSchemeLexicalClass")]
LexicalClass,
[Field ("NSLinguisticTagSchemeNameType")]
Name,
[Field ("NSLinguisticTagSchemeNameTypeOrLexicalClass")]
NameOrLexicalClass,
[Field ("NSLinguisticTagSchemeLemma")]
Lemma,
[Field ("NSLinguisticTagSchemeLanguage")]
Language,
[Field ("NSLinguisticTagSchemeScript")]
Script,
}
#if !XAMCORE_4_0
public enum NSLinguisticTagUnit {
#else
public enum NSLinguisticTag {
#endif
[Field ("NSLinguisticTagWord")]
Word,
[Field ("NSLinguisticTagPunctuation")]
Punctuation,
[Field ("NSLinguisticTagWhitespace")]
Whitespace,
[Field ("NSLinguisticTagOther")]
Other,
[Field ("NSLinguisticTagNoun")]
Noun,
[Field ("NSLinguisticTagVerb")]
Verb,
[Field ("NSLinguisticTagAdjective")]
Adjective,
[Field ("NSLinguisticTagAdverb")]
Adverb,
[Field ("NSLinguisticTagPronoun")]
Pronoun,
[Field ("NSLinguisticTagDeterminer")]
Determiner,
[Field ("NSLinguisticTagParticle")]
Particle,
[Field ("NSLinguisticTagPreposition")]
Preposition,
[Field ("NSLinguisticTagNumber")]
Number,
[Field ("NSLinguisticTagConjunction")]
Conjunction,
[Field ("NSLinguisticTagInterjection")]
Interjection,
[Field ("NSLinguisticTagClassifier")]
Classifier,
[Field ("NSLinguisticTagIdiom")]
Idiom,
[Field ("NSLinguisticTagOtherWord")]
OtherWord,
[Field ("NSLinguisticTagSentenceTerminator")]
Terminator,
[Field ("NSLinguisticTagOpenQuote")]
OpenQuote,
[Field ("NSLinguisticTagCloseQuote")]
CloseQuote,
[Field ("NSLinguisticTagOpenParenthesis")]
OpenParenthesis,
[Field ("NSLinguisticTagCloseParenthesis")]
CloseParenthesis,
[Field ("NSLinguisticTagWordJoiner")]
WordJoiner,
[Field ("NSLinguisticTagDash")]
Dash,
[Field ("NSLinguisticTagOtherPunctuation")]
OtherPunctuation,
[Field ("NSLinguisticTagParagraphBreak")]
ParagraphBreak,
[Field ("NSLinguisticTagOtherWhitespace")]
OtherWhitespace,
[Field ("NSLinguisticTagPersonalName")]
PersonalName,
[Field ("NSLinguisticTagOrganizationName")]
OrganizationName,
[Field ("NSLinguisticTagPlaceName")]
PlaceName,
}
}

Просмотреть файл

@ -4227,6 +4227,8 @@ namespace Foundation
delegate void LinguisticTagEnumerator (string tag, NSRange tokenRange, bool stop);
#if !XAMCORE_4_0
[Obsolete ("Use 'NSLinguisticTagUnit' enum instead.")]
[Static]
interface NSLinguisticTag {
[Field ("NSLinguisticTagSchemeTokenType")]
@ -4343,7 +4345,8 @@ namespace Foundation
[Field ("NSLinguisticTagOrganizationName")]
NSString OrganizationName { get; }
}
#endif
[BaseType (typeof (NSObject))]
// 'init' returns NIL so it's not usable evenif it does not throw an ObjC exception
// funnily it was "added" in iOS 7 and header files says "do not invoke; not a valid initializer for this class"
@ -8194,6 +8197,35 @@ namespace Foundation
}
delegate bool NSEnumerateLinguisticTagsEnumerator (NSString tag, NSRange tokenRange, NSRange sentenceRange, ref bool stop);
[Category]
[BaseType (typeof(NSString))]
interface NSLinguisticAnalysis {
#if XAMCORE_4_0
[return: BindAs (typeof (NSLinguisticTag []))]
#else
[return: BindAs (typeof (NSLinguisticTagUnit []))]
#endif
[EditorBrowsable (EditorBrowsableState.Advanced)]
[Export ("linguisticTagsInRange:scheme:options:orthography:tokenRanges:")]
NSString[] GetLinguisticTags (NSRange range, NSString scheme, NSLinguisticTaggerOptions options, [NullAllowed] NSOrthography orthography, [NullAllowed] out NSValue[] tokenRanges);
[Wrap ("GetLinguisticTags (This, range, scheme.GetConstant (), options, orthography, out tokenRanges)")]
#if XAMCORE_4_0
NSLinguisticTag[] GetLinguisticTags (NSRange range, NSLinguisticTagScheme scheme, NSLinguisticTaggerOptions options, [NullAllowed] NSOrthography orthography, [NullAllowed] out NSValue[] tokenRanges);
#else
NSLinguisticTagUnit[] GetLinguisticTags (NSRange range, NSLinguisticTagScheme scheme, NSLinguisticTaggerOptions options, [NullAllowed] NSOrthography orthography, [NullAllowed] out NSValue[] tokenRanges);
#endif
[EditorBrowsable (EditorBrowsableState.Advanced)]
[Export ("enumerateLinguisticTagsInRange:scheme:options:orthography:usingBlock:")]
void EnumerateLinguisticTags (NSRange range, NSString scheme, NSLinguisticTaggerOptions options, [NullAllowed] NSOrthography orthography, NSEnumerateLinguisticTagsEnumerator handler);
[Wrap ("EnumerateLinguisticTags (This, range, scheme.GetConstant (), options, orthography, handler)")]
void EnumerateLinguisticTags (NSRange range, NSLinguisticTagScheme scheme, NSLinguisticTaggerOptions options, [NullAllowed] NSOrthography orthography, NSEnumerateLinguisticTagsEnumerator handler);
}
//
// We expose NSString versions of these methods because it could
// avoid an extra lookup in cases where there is a large volume of

Просмотреть файл

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
#if XAMCORE_2_0
using Foundation;
using ObjCRuntime;
using Security;
#else
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;
using MonoTouch.Security;
#endif
using NUnit.Framework;
namespace monotouchtest
{
[TestFixture]
[Preserve (AllMembers = true)]
public class NSLinguisticAnalysisTest
{
List<NSString> words;
[SetUp]
public void SetUp ()
{
words = new List<NSString> ();
}
public bool Enumerator (NSString tag, NSRange tokenRange, NSRange sentenceRange, ref bool stop)
{
words.Add (tag);
stop = false;
return true;
}
public bool StopEnumerator (NSString tag, NSRange tokenRange, NSRange sentenceRange, ref bool stop)
{
words.Add (tag);
stop = true;
return true;
}
[Test]
public void EnumerateSubstringsInRangeTest ()
{
var testString = new NSString ("Hello Hola Bonjour!");
var range = new NSRange (0, testString.Length - 1);
testString.EnumerateLinguisticTags (range, NSLinguisticTagScheme.Token, NSLinguisticTaggerOptions.OmitWhitespace, null, Enumerator);
Assert.AreEqual (3, words.Count, "Word count");
#if XAMCORE_4_0
Assert.True (words.Contains (NSLinguisticTag.Word.GetConstant ()), "Token type.");
#else
Assert.True (words.Contains (NSLinguisticTagUnit.Word.GetConstant ()), "Token type.");
#endif
}
[Test]
public void StopEnumerateSubstringsInRangeTest ()
{
var testString = new NSString ("Hello Hola Bonjour!");
var range = new NSRange (0, testString.Length - 1);
testString.EnumerateLinguisticTags (range, NSLinguisticTagScheme.Token, NSLinguisticTaggerOptions.OmitWhitespace, null, StopEnumerator);
Assert.AreEqual (1, words.Count, "Word count");
#if XAMCORE_4_0
Assert.True (words.Contains (NSLinguisticTag.Word.GetConstant ()), "Token type.");
#else
Assert.True (words.Contains (NSLinguisticTagUnit.Word.GetConstant ()), "Token type.");
#endif
}
[Test]
public void GetLinguisticTagsTest ()
{
var testString = new NSString ("Hello Hola Bonjour!");
var range = new NSRange (0, testString.Length - 1);
NSValue[] tokenRanges;
var tags = testString.GetLinguisticTags (range, NSLinguisticTagScheme.NameOrLexicalClass, NSLinguisticTaggerOptions.OmitWhitespace, null, out tokenRanges);
Assert.AreEqual (3, tags.Length, "Tags Length");
}
}
}

Просмотреть файл

@ -9,10 +9,6 @@
## untyped enums (only values, not type name) NSError.h
!unknown-native-enum! NSUrlErrorCancelledReason bound
## NSLinguisticAnalysis category over NSString https://bugzilla.xamarin.com/show_bug.cgi?id=35009
!missing-selector! NSString::linguisticTagsInRange:scheme:options:orthography:tokenRanges: not bound
!missing-selector! NSString::enumerateLinguisticTagsInRange:scheme:options:orthography:usingBlock: not bound
## https://bugzilla.xamarin.com/show_bug.cgi?id=35021
!missing-selector! NSFileWrapper::initWithSerializedRepresentation: not bound