-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from Encamina/@rliberoff/improve_document_con…
…nectors Improve document connectors.
- Loading branch information
Showing
13 changed files
with
120 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Encamina.Enmarcha.SemanticKernel.Connectors.Document/DocumentConnectorProviderBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Text; | ||
|
||
using Encamina.Enmarcha.Core.Extensions; | ||
using Encamina.Enmarcha.SemanticKernel.Connectors.Document.Connectors; | ||
using Encamina.Enmarcha.SemanticKernel.Connectors.Document.Resources; | ||
|
||
using Microsoft.SemanticKernel.Plugins.Document; | ||
using Microsoft.SemanticKernel.Plugins.Document.OpenXml; | ||
|
||
namespace Encamina.Enmarcha.SemanticKernel.Connectors.Document; | ||
|
||
/// <summary> | ||
/// Base class to provide instances of <see cref="IDocumentConnector"/>s. | ||
/// </summary> | ||
public class DocumentConnectorProviderBase : IDocumentConnectorProvider | ||
{ | ||
private readonly Dictionary<string, IDocumentConnector> documentConnectors = new() | ||
{ | ||
{ @".DOCX", new WordDocumentConnector() }, | ||
{ @".PDF", new CleanPdfDocumentConnector() }, | ||
{ @".PPTX", new ParagraphPptxDocumentConnector() }, | ||
{ @".TXT", new TxtDocumentConnector(Encoding.UTF8) }, | ||
{ @".MD", new TxtDocumentConnector(Encoding.UTF8) }, | ||
{ @".VTT", new VttDocumentConnector(Encoding.UTF8) }, | ||
}; | ||
|
||
/// <inheritdoc/> | ||
public virtual void AddDocumentConnector(string fileExtension, IDocumentConnector documentConnector) | ||
{ | ||
documentConnectors[fileExtension.ToUpperInvariant()] = documentConnector; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public virtual IDocumentConnector GetDocumentConnector(string fileExtension) | ||
{ | ||
return GetDocumentConnector(fileExtension, true); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IDocumentConnector GetDocumentConnector(string fileExtension, bool throwException) | ||
{ | ||
if (documentConnectors.TryGetValue(fileExtension.ToUpperInvariant(), out var value)) | ||
{ | ||
return value; | ||
} | ||
|
||
if (throwException) | ||
{ | ||
throw new InvalidOperationException(ExceptionMessages.ResourceManager.GetFormattedStringByCurrentUICulture(nameof(ExceptionMessages.FileExtensionNotSupported), fileExtension)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public virtual bool SupportedFileExtension(string fileExtension) | ||
{ | ||
return documentConnectors.ContainsKey(fileExtension.ToUpperInvariant()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
src/Encamina.Enmarcha.SemanticKernel.Connectors.Document/IDocumentConnectorUtils.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters