Sqlserver
 SQL >> Database >  >> RDS >> Sqlserver

Archiviare e analizzare documenti nel file system Windows con SQL Server Semantic Search, Parte 2

Analisi comparativa dei documenti

Questa seconda parte mostra come usare Semantic Search per confrontare documenti archiviati nel file system Windows tramite una File Table. L’obiettivo è estrarre informazioni utili dai nomi e dai contenuti dei documenti.

Verifica dei documenti archiviati

È possibile controllare i documenti presenti nella File Table con:

SELECT
    stream_id,
    [name],
    file_type,
    creation_time
FROM EmployeesFilestreamSample.dbo.EmployeesDocumentStore;

Prerequisiti per Semantic Search

Per usare Semantic Search servono:

  • un indice univoco;
  • un catalogo full-text;
  • un indice full-text.

Esempio di indice univoco:

CREATE UNIQUE INDEX UQ_Stream_Id
ON EmployeesDocumentStore(stream_id);
GO

Creazione del catalogo e dell’indice full-text:

CREATE FULLTEXT CATALOG EmployeesFileTableCatalog
WITH ACCENT_SENSITIVITY = ON;

CREATE FULLTEXT INDEX ON EmployeesDocumentStore
(
    name LANGUAGE 1033 STATISTICAL_SEMANTICS,
    file_type LANGUAGE 1033 STATISTICAL_SEMANTICS,
    file_stream TYPE COLUMN file_type LANGUAGE 1033 STATISTICAL_SEMANTICS
)
KEY INDEX UQ_Stream_Id
ON EmployeesFileTableCatalog
WITH CHANGE_TRACKING AUTO, STOPLIST = SYSTEM;

Aggiungere documenti di esempio

Dalla File Table è possibile aprire la cartella con Explore FileTable Directory e creare documenti Word, ad esempio Sadaf Contract Employee e Mike Permanent Employee.

La prima riga di ogni documento dovrebbe contenere il titolo. Una denominazione standardizzata migliora l’analisi semantica.

Funzione SEMANTICKEYPHRASETABLE

La funzione SEMANTICKEYPHRASETABLE restituisce frasi chiave e punteggi associati ai documenti.

SELECT *
FROM SEMANTICKEYPHRASETABLE(EmployeesDocumentStore, name)
ORDER BY score DESC;

La funzione restituisce:

  • column_id: numero della colonna;
  • document_key: chiave primaria del documento;
  • keyphrase: frase chiave rilevante;
  • score: rilevanza della frase chiave, tra 0.0 e 1.0.

Confronto tramite SEMANTICSIMILARITYTABLE

La funzione SEMANTICSIMILARITYTABLE confronta un documento con tutti gli altri.

SELECT
    SST.source_column_id,
    SST.matched_column_id,
    EDS.name,
    SCORE
FROM SEMANTICSIMILARITYTABLE
(
    EmployeesDocumentStore,
    name,
    0xFF6A92952500812FF013376870181CFA6D7C070220
) SST
INNER JOIN dbo.EmployeesDocumentStore EDS
    ON EDS.path_locator = SST.matched_document_key
ORDER BY score DESC;

Conclusione

Semantic Search consente di archiviare e analizzare documenti non strutturati usando SQL Server e File Table. Una denominazione coerente dei documenti è fondamentale per ottenere risultati accurati.