owenG
home learn tableau about
divider
legalific swsom swsom diagram swapps ahk ue








swsom wrapper
[Overview] Application - CurrentNote DB - Notes ocrBase - OpenTranscripts Permission - Views
 
Download :: Diagram
swsom wrapper

ocrBase

Handful of properties plus several methods. The example performs an ocrBase search and then iteratest through the records, recording the Docid and then the line of ocr text on which the hit took place. Will only take note of a hit once, even if the search term occurs twice on same line:

VB
    Dim ocrBaseView As sw.Views.View = New sw.Views.View("ocrBase")
    ocrBaseView.Activate()

    Dim searchTerm As String = "construction"
    Dim lineText, linesInDoc As String
    Dim thisLineText As String = ""
    Dim allDocs As String = "Hits report:" & vbCrLf
    Dim docidField As New sw.DB.Field(sw.DB.Defaults.BegDoc)
    Dim isLast As Boolean = False

    sw.ocrBase.Search(searchTerm)
    Do
        sw.ocrBase.FindFirst(searchTerm)
        lineText = sw.ocrBase.Line
        linesInDoc = "Docid: " & docidField.Value & vbCrLf & ">> " & lineText
        Do While lineText <> thisLineText
            linesInDoc += thisLineText & vbCrLf
            lineText = ">> " & sw.ocrBase.Line 'thisLineText
            sw.ocrBase.FindNext(searchTerm)
            thisLineText = ">> " & sw.ocrBase.Line
        Loop
        thisLineText = ""
        allDocs += linesInDoc & vbCrLf & vbCrLf

        If sw.ocrBase.IsLast Then
            isLast = True
        Else
            sw.ocrBase.MoveNext()
        End If

    Loop Until isLast
    MessageBox.Show(allDocs)

ocrBase.Selection

The Selection object was only listed once in the XML documentation, where it was nested under Transcript. The properties and methods are the same though, whether the Selection is from a Transcript or the ocrBase, so I simply copied the generated code from the Transcript.Selection.vb into a new ocrBase.Selection.vb file and updated the description text to reference ocrBase. Example is similar to above, but retrieves the line before and after the hit via Selection.GetExcerpt.

VB
    Dim ocrBaseView As sw.Views.View = New sw.Views.View("ocrBase")
    ocrBaseView.Activate()

    Dim searchTerm As String = "construction"
    Dim linesInDoc As String
    Dim excerptText As String = ""
    Dim allDocs As String = "Hits report:" & vbCrLf
    Dim docidField As New sw.DB.Field(sw.DB.Defaults.BegDoc)
    Dim isLast As Boolean = False
    Dim thisLineNumber, lineNumber As Integer

    sw.ocrBase.Search(searchTerm)
    Do
        sw.ocrBase.FindFirst(searchTerm)
        lineNumber = sw.ocrBase.Selection.AbsoluteLine
        excerptText = ">> Hit on page: " & sw.ocrBase.Selection.Page & " line: " & _
                sw.ocrBase.Selection.Line & vbCrLf & sw.ocrBase.Selection.GetExcerpt(1)
        linesInDoc = "Docid: " & docidField.Value & vbCrLf & vbCrLf
        Do While lineNumber <> thisLineNumber
            linesInDoc += excerptText & vbCrLf & vbCrLf
            lineNumber = sw.ocrBase.Selection.AbsoluteLine
            sw.ocrBase.FindNext(searchTerm)
            thisLineNumber = sw.ocrBase.Selection.AbsoluteLine
            excerptText = ">> Hit on page: " & sw.ocrBase.Selection.Page & " line: " & _
                sw.ocrBase.Selection.Line & vbCrLf & sw.ocrBase.Selection.GetExcerpt(1)
        Loop

        thisLineNumber = 0
        allDocs += linesInDoc & vbCrLf & vbCrLf

        If sw.ocrBase.IsLast Then
            isLast = True
        Else
            sw.ocrBase.MoveNext()
        End If

    Loop Until isLast
    MessageBox.Show(allDocs)

The Extend method in ocrBase.Selection was operating in a strange and hopefully rare manner, where a (False) Boolean could not be passed directly into Summation from VB. Instead, if False were used as the last parameter the Selection direction would still be Forward and not the Backwards direction that the documentation says should be happening. Casting the Boolean into an Integer on the swsom side before passing didn't work, nor did assigning a 0 value to an Integer variable within swsom and passing the variable. Instead, it seemed the only way to get the backwards direction was to use a true 0 as the last parameter, see below for the code definition that worked.

VB
    Public Shared Sub Extend(ByVal Type As Integer, ByVal numToExtend As Integer, ByVal 
      Direction As Boolean)
        If Direction Then
            sw.swObj.ocrBase.Selection.Extend(Type, numToExtend, 1)
        Else
            sw.swObj.ocrBase.Selection.Extend(Type, numToExtend, 0)
        End If
    End Sub

OpenTranscripts

Parent OpenTranscript object is primarily a holder for its sub-classes, has only a few properties (including Item as a Default Property) and no methods.

C#
    int openTranCount = sw.OpenTranscripts.Count;
    if (openTranCount > 0)
    {
        long pFrancIndex = sw.OpenTranscripts.Find("Peter franc v1.txt");
        if (pFrancIndex > 0)
        {
            MessageBox.Show(String.Format("P. Franc transcript is open, #{0} of {1}", 
                pFrancIndex, openTranCount));
            //use Default Property (Item)
            sw.OpenTranscripts openTran = new sw.OpenTranscripts();
            string pfrancDescription = openTran[pFrancIndex].Description;
        }
    }

OpenTranscripts.Transcript

There are essentially two ways of creating a Transcript object, where the first uses an index (string or number) while the second is useful only if the transcript in question is the Active View. First example creates the transcript object via an Integer index:

C#
    long pFrancIndex = sw.OpenTranscripts.Find("Peter franc v1.txt");
    if (pFrancIndex > 0)
    {
        sw.OpenTranscripts.Transcript pfranc = new sw.OpenTranscripts.Transcript(pFrancIndex);
        int page = 20, line = 1;
        pfranc.SetCaret(page, line, 0);
        int typeWord = 2;
        bool inForwardDirection = true;
        //skip the line number, which counts as first word
        pfranc.MoveCaret(typeWord, 2, inForwardDirection); 
        bool skipToWord = true;
        string wordAtCaret = pfranc.WordAtCaret(skipToWord);
        MessageBox.Show(String.Format("{0} is open, word at page {1}, line {2} is: \"{3}\"",
            pfranc.Description, page, line, wordAtCaret));
     }

and now by instantiating Transcript with a string (the transcript file name, not the description):

C#
    sw.OpenTranscripts.Transcript pfranc = new sw.OpenTranscripts.Transcript("Peter franc v1.txt");
    string description = "";
    try
    {
        description = pfranc.Description;
    }
    catch (Exception ex)
    {
        //error creating Transcript object 
        throw ex;
    }
    int page = 20, line = 1;
    pfranc.SetCaret(page, line, 0);
    int typeWord = 2;
    bool inForwardDirection = true;
    //skip the line number, which counts as first word
    pfranc.MoveCaret(typeWord, 2, inForwardDirection); 
    bool skipToWord = true;
    string wordAtCaret = pfranc.WordAtCaret(skipToWord);
    MessageBox.Show(String.Format("{0} is open, word at page {1}, line {2} is: \"{3}\"", 
        description, page, line, wordAtCaret));

And finally the Transcript object can be accessed if it is known to be the Active View, via a new property added to the Views object, ActiveView_AsTranscript. When a Boolean value of True is passed into the Transcript constructor, each property and method will then access the Views.ActiveView object of Summation in order to execute. For example, AddNewNote is currently written as below, where the _isActiveView field should only be True if the given Transcript object were created by using Views.ActiveView_AsTranscript:

C#
    Public Sub AddNewNote(ByVal lineNumber As Integer)
        If _isActiveView Then
            sw.swObj.Views.ActiveView.AddNewNote(lineNumber)
        Else
            sw.swObj.OpenTranscripts(_index).AddNewNote(lineNumber)
        End If
    End Sub

And as an example of this usage, which will fail internally if the Active View is NOT a Transcript:

C#
     sw.OpenTranscripts.Transcript activeTran = sw.Views.ActiveView_AsTranscript;
     string description = activeTran.Description;
     activeTran.AddNewNote(10);

OpenTranscripts.Transcript.Links

Holder of Link objects for a given Transcript, no methods directly within and only two properties: Count and (Default Property) Item.

C#
    string fileName = "Peter franc v1.txt";
    sw.OpenTranscripts.Transcript.Links links = new sw.OpenTranscripts.Transcript.Links(fileName);
    int count = links.Count;
    MessageBox.Show(pFrancFilename + " has " + count + " links");

OpenTranscripts.Transcript.Links.Link

Represents one Link within the Links collection for a given transcript. The properties were originally auto-generated with parameters, where the documented syntax for each showed that they could be accessed either directly or with a parameter. I re-wrote so only direct assignation was allowed. Only has three methods, two of which (Perform, Execute) do the same thing. One would generally work with links through the parent Transcript object, below runs through the links in the P. Franc transcript and executes any that were set to open a Document Image Tag:

C#
    string fileName = "Peter franc v1.txt";
    sw.OpenTranscripts.Transcript.Links links = new sw.OpenTranscripts.Transcript.Links(fileName);
    int count = links.Count;
    for (int i = 1; i <= count; i++)
    {
        string action = links[i].Action;
        if (action.StartsWith("ShowImageDocument", StringComparison.InvariantCultureIgnoreCase))
        {
            links[i].Execute();
            sw.Application.Delay(2000);
        }
    }

And it is also possible to access a link directly, using the transcript index (int or string) followed by the link index:

C#
    sw.OpenTranscripts.Transcript.Links.Link link = new sw.OpenTranscripts.Transcript.Links.Link(1, 1);
    string actionOfFirstLinkInFirstOpenTranscript = link.Action;

OpenTranscripts.Transcript.Selection

The properties and methods for the Selection object in OpenTranscripts.Transcript are essentially the same as with ocrBase.Selection but since there are potentially multiple parent Transcript objects available, as opposed to the singular ocrBase view, .Selection here has been written via instance methods. As with .Links, you can instantiate with either an (integer) index or via transcript file name:

C#
    long pFrancIndex = sw.OpenTranscripts.Find("Peter franc v1.txt");
    if (pFrancIndex > 0)
    {
        sw.OpenTranscripts.Transcript pFrancTran = new sw.OpenTranscripts.Transcript(pFrancIndex);
        pFrancTran.FindFirst("911");
        sw.OpenTranscripts.Transcript.Selection pfrancSelection = new 
            sw.OpenTranscripts.Transcript.Selection(pFrancIndex);
        string excerpt = pfrancSelection.GetExcerpt(1);
    }