コード例 #1
0
        /// <summary>
        /// Initializes the Mixed Reality Extension SDK API.
        /// </summary>
        /// <param name="defaultMaterial">The material template used for all SDK-spawned meshes.</param>
        /// <param name="behaviorFactory">The behavior factory to use within the runtime.</param>
        /// <param name="textFactory">The text factory to use within the runtime.</param>
        /// <param name="primitiveFactory">The primitive factory to use within the runtime.</param>
        /// <param name="libraryFactory">The library resource factory to use within the runtime.</param>
        /// <param name="assetCache">The place for this MRE to cache its meshes, etc.</param>
        /// <param name="gltfImporterFactory">The glTF loader factory. Uses default GLTFSceneImporter if omitted.</param>
        /// <param name="materialPatcher">Overrides default material property map (color and mainTexture only).</param>
        /// <param name="userInfoProvider">Provides appId/sessionId scoped IUserInfo instances.</param>
        /// <param name="engineConstants">Engine constants supplied by the host app.</param>
        /// <param name="logger">The logger to be used by the MRE SDK.</param>
        public static void InitializeAPI(
            UnityEngine.Material defaultMaterial,
            IBehaviorFactory behaviorFactory       = null,
            ITextFactory textFactory               = null,
            IPrimitiveFactory primitiveFactory     = null,
            ILibraryResourceFactory libraryFactory = null,
            IAssetCache assetCache = null,
            IGLTFImporterFactory gltfImporterFactory = null,
            IMaterialPatcher materialPatcher         = null,
            IUserInfoProvider userInfoProvider       = null,
            IEngineConstants engineConstants         = null,
            IMRELogger logger = null)
        {
            AppsAPI.DefaultMaterial        = defaultMaterial;
            AppsAPI.BehaviorFactory        = behaviorFactory;
            AppsAPI.TextFactory            = textFactory ?? throw new ArgumentException($"{nameof(textFactory)} cannot be null");
            AppsAPI.PrimitiveFactory       = primitiveFactory ?? new MWPrimitiveFactory();
            AppsAPI.LibraryResourceFactory = libraryFactory;
            AppsAPI.AssetCache             = assetCache ?? new AssetCache();
            AppsAPI.GLTFImporterFactory    = gltfImporterFactory ?? new GLTFImporterFactory();
            AppsAPI.MaterialPatcher        = materialPatcher ?? new DefaultMaterialPatcher();
            AppsAPI.UserInfoProvider       = userInfoProvider ?? new NullUserInfoProvider();
            AppsAPI.EngineConstants        = engineConstants;

#if ANDROID_DEBUG
            Logger = logger ?? new UnityLogger();
#else
            Logger = logger ?? new ConsoleLogger();
#endif
        }
コード例 #2
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document) {
            if (document.Sentences == null)
                throw new AnalyzerException(this, "The document does not have the sentences detected.");

            foreach (var sentence in document.Sentences) {
                if (sentence.Tokens == null)
                    throw new AnalyzerException(this, "The document have a sentence without the tokenization.");

                string[] tags;
                double[] probs;
                object[]  ac = AddContextProvider != null
                    ? AddContextProvider(document, sentence)
                    : null;

                lock (Tagger) {
                    tags = Tagger.Tag(sentence.Tokens.ToTokenArray(), ac);
                    probs = Tagger.Probabilities;
                }

                var prob = probs.Sum(p => p);
                if (probs.Length > 0)
                    prob /= probs.Length;

                for (var i = 0; i < tags.Length; i++) {
                    sentence.Tokens[i].POSTag = tags[i];
                    sentence.Tokens[i].POSTagProbability = probs[i];
                }

                // TODO: Add the ability to pre/post process each sentence during the analysis.

                sentence.TagProbability = prob;
            }
        }
コード例 #3
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document)
        {
            if (document.Sentences == null)
            {
                throw new AnalyzerException(this, "The document does not have the sentences detected.");
            }

            foreach (var sentence in document.Sentences)
            {
                if (sentence.Tokens == null)
                {
                    throw new AnalyzerException(this, "The document have a sentence without the tokenization.");
                }

                var list = sentence.Categories != null
                    ? new List <ICategory>(sentence.Categories)
                    : new List <ICategory>();

                var dict     = DocumentCategorizer.ScoreMap(sentence.GetTokens());
                var category = factory.CreateCategory(sentence, dict);
                if (category != null && !list.Contains(category))
                {
                    list.Add(category);
                }

                sentence.Categories = new ReadOnlyCollection <ICategory>(list);
            }
        }
コード例 #4
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document)
        {
            if (string.IsNullOrEmpty(document.Text))
            {
                throw new AnalyzerException(this, "The document text is null or empty.");
            }

            Span[] spans;
            lock (SentenceDetector) {
                spans = SentenceDetector.SentPosDetect(document.Text);
            }

            var list = new List <ISentence>(spans.Length);

            foreach (var span in spans)
            {
                var sentence = factory.CreateSentence(span, document);

                if (sentence != null)
                {
                    list.Add(sentence);
                }
            }


            document.Sentences = new ReadOnlyCollection <ISentence>(list);
        }
コード例 #5
0
        /// <summary>
        /// Analyzes the specified document which can be several sentences, a sentence or even a single word.
        /// </summary>
        /// <param name="factory">
        /// The text factory. if this argument is <c>null</c> the <see cref="DefaultTextFactory" /> must
        /// be used during the analysis.
        /// </param>
        /// <param name="document">The <see cref="IDocument" /> to be analyzed.</param>
        public void Analyze(ITextFactory factory, IDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            if (document.Sentences == null || document.Sentences.Count == 0)
            {
                throw new InvalidOperationException("The document does not have any sentences detected.");
            }

            if (document.Sentences[0].Tokens == null || document.Sentences[0].Tokens.Count == 0)
            {
                throw new InvalidOperationException("The document is not tokenized.");
            }


            // TODO: Implement with the new lemmatizer.
            throw new NotImplementedException();

            /*
             * foreach (var sentence in document.Sentences)
             *  foreach (var token in sentence.Tokens)
             *      token.Lemmas = lemmatizer.Lemmatize(token.Lexeme, token.POSTag);
             */
        }
コード例 #6
0
ファイル: LemmatizerAnalyzer.cs プロジェクト: qooba/SharpNL
        /// <summary>
        /// Analyzes the specified document which can be several sentences, a sentence or even a single word.
        /// </summary>
        /// <param name="factory">The text factory. if this argument is <c>null</c> the <see cref="DefaultTextFactory"/> must
        /// be used during the analysis.</param>
        /// <param name="document">The <see cref="IDocument" /> to be analyzed.</param>
        public void Analyze(ITextFactory factory, IDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            if (document.Sentences == null || document.Sentences.Count == 0)
            {
                throw new InvalidOperationException("The document does not have any sentences detected.");
            }

            if (document.Sentences[0].Tokens == null || document.Sentences[0].Tokens.Count == 0)
            {
                throw new InvalidOperationException("The document is not tokenized.");
            }

            foreach (var sentence in document.Sentences)
            {
                foreach (var token in sentence.Tokens)
                {
                    token.Lemmas = lemmatizer.Lemmatize(token.Lexeme, token.POSTag);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Initializes the Mixed Reality Extension SDK API.
        /// </summary>
        /// <param name="defaultMaterial">The material template used for all SDK-spawned meshes.</param>
        /// <param name="layerApplicator">The class used to apply MRE layers to Unity colliders.</param>
        /// <param name="behaviorFactory">The behavior factory to use within the runtime.</param>
        /// <param name="textFactory">The text factory to use within the runtime.</param>
        /// <param name="primitiveFactory">The primitive factory to use within the runtime.</param>
        /// <param name="libraryFactory">The library resource factory to use within the runtime.</param>
        /// <param name="gltfImporterFactory">The glTF loader factory. Uses default GLTFSceneImporter if omitted.</param>
        /// <param name="materialPatcher">Overrides default material property map (color and mainTexture only).</param>
        /// <param name="videoPlayerFactory"></param>
        /// <param name="userInfoProvider">Provides appId/sessionId scoped IUserInfo instances.</param>
        /// <param name="dialogFactory"></param>
        /// <param name="logger">The logger to be used by the MRE SDK.</param>
        public static void InitializeAPI(
            UnityEngine.Material defaultMaterial,
            ILayerApplicator layerApplicator,
            IBehaviorFactory behaviorFactory         = null,
            ITextFactory textFactory                 = null,
            IPrimitiveFactory primitiveFactory       = null,
            ILibraryResourceFactory libraryFactory   = null,
            IGLTFImporterFactory gltfImporterFactory = null,
            IMaterialPatcher materialPatcher         = null,
            IVideoPlayerFactory videoPlayerFactory   = null,
            IUserInfoProvider userInfoProvider       = null,
            IDialogFactory dialogFactory             = null,
            IMRELogger logger = null)
        {
            AppsAPI.DefaultMaterial        = defaultMaterial;
            AppsAPI.LayerApplicator        = layerApplicator;
            AppsAPI.BehaviorFactory        = behaviorFactory;
            AppsAPI.TextFactory            = textFactory ?? throw new ArgumentException($"{nameof(textFactory)} cannot be null");
            AppsAPI.PrimitiveFactory       = primitiveFactory ?? new MWPrimitiveFactory();
            AppsAPI.LibraryResourceFactory = libraryFactory;
            AppsAPI.VideoPlayerFactory     = videoPlayerFactory;
            AppsAPI.GLTFImporterFactory    = gltfImporterFactory ?? new GLTFImporterFactory();
            AppsAPI.MaterialPatcher        = materialPatcher ?? new DefaultMaterialPatcher();
            AppsAPI.UserInfoProvider       = userInfoProvider ?? new NullUserInfoProvider();
            AppsAPI.DialogFactory          = dialogFactory;

#if ANDROID_DEBUG
            Logger = logger ?? new UnityLogger(null);
#else
            Logger = logger ?? new ConsoleLogger(null);
#endif
        }
コード例 #8
0
        /// <summary>
        /// Analyzes the specified document which can be several sentences, a sentence or even a single word.
        /// </summary>
        /// <param name="factory">The text factory. if this argument is <c>null</c> the <see cref="DefaultTextFactory" /> will be used during the analysis.</param>
        /// <param name="document">The <see cref="IDocument" /> to be analyzed.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="document"/>
        /// </exception>
        public void Analyze(ITextFactory factory, IDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            Evaluate(factory ?? DefaultTextFactory.Instance, document);
        }
コード例 #9
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document) {
            if (document.Sentences == null)
                throw new AnalyzerException(this, "The document does not have the sentences detected.");

            foreach (var sentence in document.Sentences) {
                var p = ParserTool.ParseLine(sentence, Parser, 1);
                if (p != null && p.Length > 0)
                    sentence.Parse = p[0];
            }
        }
コード例 #10
0
 /// <summary>
 /// Analyzes the specified document which can be several sentences, a sentence or even a single word.
 /// </summary>
 /// <param name="factory">The text factory. if this argument is <c>null</c> the <see cref="DefaultTextFactory"/> must
 /// be used during the analysis.</param>
 /// <param name="document">The <see cref="IDocument" /> to be analyzed.</param>
 public void Analyze(ITextFactory factory, IDocument document)
 {
     lock (document) {
         foreach (var analyzer in Analyzers)
         {
             try {
                 analyzer.Analyze(factory, document);
             } catch (Exception ex) {
                 throw new AnalyzerException(analyzer, "The analyzer raised an exception.", ex);
             }
         }
     }
 }
コード例 #11
0
ファイル: LemmatizerAnalyzer.cs プロジェクト: knuppe/SharpNL
        /// <summary>
        /// Analyzes the specified document which can be several sentences, a sentence or even a single word.
        /// </summary>
        /// <param name="factory">The text factory. if this argument is <c>null</c> the <see cref="DefaultTextFactory"/> must 
        /// be used during the analysis.</param>
        /// <param name="document">The <see cref="IDocument" /> to be analyzed.</param>
        public void Analyze(ITextFactory factory, IDocument document) {
            if (document == null)
                throw new ArgumentNullException("document");

            if (document.Sentences == null || document.Sentences.Count == 0)
                throw new InvalidOperationException("The document does not have any sentences detected.");

            if (document.Sentences[0].Tokens == null || document.Sentences[0].Tokens.Count == 0)
                throw new InvalidOperationException("The document is not tokenized.");

            foreach (var sentence in document.Sentences)
                foreach (var token in sentence.Tokens)
                    token.Lemmas = lemmatizer.Lemmatize(token.Lexeme, token.POSTag);

        }
コード例 #12
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document)
        {
            if (document.Sentences == null)
            {
                throw new AnalyzerException(this, "The document does not have the sentences detected.");
            }

            foreach (var sentence in document.Sentences)
            {
                var p = ParserTool.ParseLine(sentence, Parser, 1);
                if (p != null && p.Length > 0)
                {
                    sentence.Parse = p[0];
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document)
        {
            if (document.Sentences == null)
            {
                throw new AnalyzerException(this, "The document does not have the sentences detected.");
            }

            foreach (var sentence in document.Sentences)
            {
                var toks = sentence.GetTokens();
                var tags = sentence.GetTags();

                if (toks == null)
                {
                    throw new AnalyzerException(this, "The document have a sentence without the tokenization.");
                }

                if (tags == null)
                {
                    throw new AnalyzerException(this, "The document have a sentence without the part-of-speech tags.");
                }

                string[] chunks;
                lock (Chunker) {
                    chunks = Chunker.Chunk(toks, tags);
                }

                for (var i = 0; i < chunks.Length; i++)
                {
                    sentence.Tokens[i].ChunkTag = chunks[i];
                }

                var spans = ChunkSample.PhrasesAsSpanList(toks, tags, chunks);
                var list  = new List <IChunk>(spans.Length);

                foreach (var span in spans)
                {
                    var chunk = factory.CreateChunk(sentence, span);
                    if (chunk != null)
                    {
                        list.Add(chunk);
                    }
                }

                sentence.Chunks = new ReadOnlyCollection <IChunk>(list);
            }
        }
コード例 #14
0
        /// <summary>
        /// Initializes the Mixed Reality Extension SDK API.
        /// </summary>
        /// <param name="defaultMaterial">The material template used for all SDK-spawned meshes.</param>
        /// <param name="layerApplicator">The class used to apply MRE layers to Unity colliders.</param>
        /// <param name="assetCache">The class responsible for long-term asset caching.</param>
        /// <param name="textFactory">The text factory to use within the runtime.</param>
        /// <param name="permissionManager">The instance responsible for presenting users with permission requests.</param>
        /// <param name="behaviorFactory">The behavior factory to use within the runtime.</param>
        /// <param name="dialogFactory"></param>
        /// <param name="libraryFactory">The library resource factory to use within the runtime.</param>
        /// <param name="videoPlayerFactory"></param>
        /// <param name="primitiveFactory">The primitive factory to use within the runtime.</param>
        /// <param name="gltfImporterFactory">The glTF loader factory. Uses default GLTFSceneImporter if omitted.</param>
        /// <param name="materialPatcher">Overrides default material property map (color and mainTexture only).</param>
        /// <param name="userInfoProvider">Provides appId/sessionId scoped IUserInfo instances.</param>
        /// <param name="logger">The logger to be used by the MRE SDK.</param>
        public static void InitializeAPI(
            // required properties
            SpatialMaterial defaultMaterial,
            ILayerApplicator layerApplicator,
            IAssetCache assetCache,
            ITextFactory textFactory,
            IPermissionManager permissionManager,
            // missing features if omitted
            IBehaviorFactory behaviorFactory = null,
            //IDialogFactory dialogFactory = null,
            ILibraryResourceFactory libraryFactory = null,
            //IVideoPlayerFactory videoPlayerFactory = null,
            // reasonable defaults provided
            IPrimitiveFactory primitiveFactory       = null,
            IGLTFImporterFactory gltfImporterFactory = null,
            IMaterialPatcher materialPatcher         = null,
            IMRELogger logger = null)
        {
            // required properties
            AppsAPI.DefaultMaterial   = defaultMaterial;
            AppsAPI.LayerApplicator   = layerApplicator;
            AppsAPI.AssetCache        = assetCache;
            AppsAPI.TextFactory       = textFactory;
            AppsAPI.PermissionManager = permissionManager;

            // missing features if omitted
            AppsAPI.BehaviorFactory = behaviorFactory;
            //AppsAPI.DialogFactory = dialogFactory;
            AppsAPI.LibraryResourceFactory = libraryFactory;
            //AppsAPI.VideoPlayerFactory = videoPlayerFactory;

            // reasonable defaults provided
            AppsAPI.PrimitiveFactory    = primitiveFactory ?? new MWPrimitiveFactory();
            AppsAPI.GLTFImporterFactory = gltfImporterFactory ?? new GLTFImporterFactory();
            AppsAPI.MaterialPatcher     = materialPatcher ?? new DefaultMaterialPatcher();

#if ANDROID_DEBUG
            Logger = logger ?? new UnityLogger(null);
#else
            Logger = logger ?? new ConsoleLogger(null);
#endif
        }
コード例 #15
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document)
        {
            if (document.Sentences == null)
            {
                throw new AnalyzerException(this, "The document does not have the sentences detected.");
            }

            foreach (var sentence in document.Sentences)
            {
                if (sentence.Tokens == null)
                {
                    throw new AnalyzerException(this, "The document have a sentence without the tokenization.");
                }

                string[] tags;
                double[] probs;
                object[] ac = AddContextProvider != null
                    ? AddContextProvider(document, sentence)
                    : null;

                lock (Tagger) {
                    tags  = Tagger.Tag(sentence.Tokens.ToTokenArray(), ac);
                    probs = Tagger.Probabilities;
                }

                var prob = probs.Sum(p => p);
                if (probs.Length > 0)
                {
                    prob /= probs.Length;
                }

                for (var i = 0; i < tags.Length; i++)
                {
                    sentence.Tokens[i].POSTag            = tags[i];
                    sentence.Tokens[i].POSTagProbability = probs[i];
                }

                // TODO: Add the ability to pre/post process each sentence during the analysis.

                sentence.TagProbability = prob;
            }
        }
コード例 #16
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document) {
            if (document.Sentences == null)
                throw new AnalyzerException(this, "The document does not have the sentences detected.");

            foreach (var sentence in document.Sentences) {
                if (sentence.Tokens == null)
                    throw new AnalyzerException(this, "The document have a sentence without the tokenization.");

                var list = sentence.Categories != null
                    ? new List<ICategory>(sentence.Categories)
                    : new List<ICategory>();

                var dict = DocumentCategorizer.ScoreMap(sentence.GetTokens());
                var category = factory.CreateCategory(sentence, dict);
                if (category != null && !list.Contains(category))
                    list.Add(category);

                sentence.Categories = new ReadOnlyCollection<ICategory>(list);
            }
        }
コード例 #17
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document) {

            if (string.IsNullOrEmpty(document.Text))
                throw new AnalyzerException(this, "The document text is null or empty.");

            Span[] spans;
            lock (SentenceDetector) {
                spans = SentenceDetector.SentPosDetect(document.Text);
            }

            var list = new List<ISentence>(spans.Length);
            foreach (var span in spans) {
                var sentence = factory.CreateSentence(span, document);

                if (sentence != null)
                    list.Add(sentence);
            }


            document.Sentences = new ReadOnlyCollection<ISentence>(list);
        }
コード例 #18
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document)
        {
            if (document.Sentences == null)
            {
                throw new AnalyzerException(this, "The document does not have the sentences detected.");
            }

            foreach (var sentence in document.Sentences)
            {
                if (sentence.Tokens == null)
                {
                    throw new AnalyzerException(this, "The document have a sentence without the tokenization.");
                }

                Span[] spans;
                lock (NameFinder) {
                    spans = NameFinder.Find(sentence.Tokens.ToTokenArray());
                }

                if (spans == null || spans.Length == 0)
                {
                    sentence.Entities = new ReadOnlyCollection <IEntity>(new IEntity[] { });
                    continue;
                }

                var list = new List <IEntity>(spans.Length);

                // ReSharper disable once LoopCanBeConvertedToQuery
                foreach (var span in spans)
                {
                    var entity = factory.CreateEntity(sentence, span);
                    if (entity != null)
                    {
                        list.Add(entity);
                    }
                }

                sentence.Entities = new ReadOnlyCollection <IEntity>(list);
            }
        }
コード例 #19
0
ファイル: TokenizerAnalyzer.cs プロジェクト: qooba/SharpNL
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document)
        {
            if (document.Sentences == null)
            {
                throw new AnalyzerException(this, "The document does not have the sentences detected.");
            }

            foreach (var sentence in document.Sentences)
            {
                var text = sentence.Text;

                if (string.IsNullOrWhiteSpace(text) || (PreProcess && (text = PreProcessSentence(document.Language, text)) == null))
                {
                    sentence.Tokens = new ReadOnlyCollection <IToken>(new IToken[] { });
                    continue;
                }

                Span[] spans;
                lock (Tokenizer) {
                    spans = Tokenizer.TokenizePos(text);
                }

                if (spans == null || spans.Length == 0)
                {
                    sentence.Tokens = new ReadOnlyCollection <IToken>(new IToken[] {});
                }
                else
                {
                    var list = new List <IToken>(spans.Length);
                    list.AddRange(spans
                                  .Select(span => factory.CreateToken(sentence, span, span.GetCoveredText(text)))
                                  .Where(token => token != null));

                    sentence.Tokens = new ReadOnlyCollection <IToken>(list);
                }
            }
        }
コード例 #20
0
ファイル: ChunkerAnalyzer.cs プロジェクト: knuppe/SharpNL
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document) {
            if (document.Sentences == null)
                throw new AnalyzerException(this, "The document does not have the sentences detected.");

            foreach (var sentence in document.Sentences) {
                var toks = sentence.GetTokens();
                var tags = sentence.GetTags();

                if (toks == null)
                    throw new AnalyzerException(this, "The document have a sentence without the tokenization.");

                if (tags == null)
                    throw new AnalyzerException(this, "The document have a sentence without the part-of-speech tags.");

                string[] chunks;
                lock (Chunker) {
                    chunks = Chunker.Chunk(toks, tags);
                }

                for (var i = 0; i < chunks.Length; i++) {
                    sentence.Tokens[i].ChunkTag = chunks[i];
                }

                var spans = ChunkSample.PhrasesAsSpanList(toks, tags, chunks);
                var list = new List<IChunk>(spans.Length);

                foreach (var span in spans) {
                    var chunk = factory.CreateChunk(sentence, span);
                    if (chunk != null)
                        list.Add(chunk);

                }

                sentence.Chunks = new ReadOnlyCollection<IChunk>(list);
            }
        }
コード例 #21
0
 /// <summary>
 /// Evaluates the specified document.
 /// </summary>
 /// <param name="factory">The factory used in this analysis.</param>
 /// <param name="document">The document to be analyzed.</param>
 protected abstract void Evaluate(ITextFactory factory, IDocument document);
コード例 #22
0
        /// <summary>
        /// Evaluates the specified document.
        /// </summary>
        /// <param name="factory">The factory used in this analysis.</param>
        /// <param name="document">The document to be analyzed.</param>
        protected override void Evaluate(ITextFactory factory, IDocument document) {
            if (document.Sentences == null)
                throw new AnalyzerException(this, "The document does not have the sentences detected.");

            foreach (var sentence in document.Sentences) {
                var text = sentence.Text;

                if (string.IsNullOrWhiteSpace(text) || (PreProcess && (text = PreProcessSentence(document.Language, text)) == null)) {
                    sentence.Tokens = new ReadOnlyCollection<IToken>(new IToken[] { });
                    continue;
                }

                Span[] spans;
                lock (Tokenizer) {
                    spans = Tokenizer.TokenizePos(text);
                }

                if (spans == null || spans.Length == 0) {
                    sentence.Tokens = new ReadOnlyCollection<IToken>(new IToken[] {});
                } else {
                    var list = new List<IToken>(spans.Length);
                    list.AddRange(spans
                        .Select(span => factory.CreateToken(sentence, span, span.GetCoveredText(text)))
                        .Where(token => token != null));

                    sentence.Tokens = new ReadOnlyCollection<IToken>(list);
                }
            }
        }
コード例 #23
0
ファイル: AbstractAnalyzer.cs プロジェクト: knuppe/SharpNL
 /// <summary>
 /// Evaluates the specified document.
 /// </summary>
 /// <param name="factory">The factory used in this analysis.</param>
 /// <param name="document">The document to be analyzed.</param>
 protected abstract void Evaluate(ITextFactory factory, IDocument document);
コード例 #24
0
ファイル: AbstractAnalyzer.cs プロジェクト: knuppe/SharpNL
        /// <summary>
        /// Analyzes the specified document which can be several sentences, a sentence or even a single word.
        /// </summary>
        /// <param name="factory">The text factory. if this argument is <c>null</c> the <see cref="DefaultTextFactory" /> will be used during the analysis.</param>
        /// <param name="document">The <see cref="IDocument" /> to be analyzed.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="document"/>
        /// </exception>
        public void Analyze(ITextFactory factory, IDocument document) {
            if (document == null)
                throw new ArgumentNullException("document");

            Evaluate(factory ?? DefaultTextFactory.Instance, document);
        }