Fill in (DeOutline) what was Exported as Outline

Have new ideas for the next release of IHMC CmapTools and IHMC CmapServer?
We welcome your suggestions and we will carefully consider whether to incorporate them into the software.
Post Reply
Posts: 1
Joined: Mon Apr 23, 2018 8:55 am

Fill in (DeOutline) what was Exported as Outline

Post by dakra137 » Mon Apr 23, 2018 9:24 am

I love the Export as Outline and Propositions as Text capability. However, sometimes what I want is every line to have every concept from the beginning of a sequence to the "current" one. Other times, I want only complete sequences from a beginning to an end meaning that I don't want partially traversed paths from a beginning of the sequence to an intermediate stopping point.

If the outline is:

Code: Select all

		a sentence
Sometimes I want

Code: Select all

This	is
This	is	a sentence
This	is	a sentence	.}
but usually I want only

Code: Select all

This	is	a sentence	.}
I use the } symbol to indicate the end of a sequence

Here below is a script in the awk language that could do either assignment, depending on which line near the end is uncommented. Awk is available for Windows, linux, and most other operating systems.

Code: Select all

#!/usr/bin/gawk -f
# Copyright 2018 David A. Kra granting Creative Commons Share Alike license to all users. See 
# usage syntax #1: gawk -f deoutline.awk 'fullpathname' >deoutlined.txt
# usage syntax #2: ./deoutline.awk 'fullpathname' >deoutlined.txt
# Purpose: Converts a CMAPTools outline into a set of complete lines, where a "complete line" is one that ends with "}".
# Processes output produced by CMAPTools menu sequence: File  | Export CMAP As... | CMAP Outline... .
# Input: outline: each line starts with n (0 <= n) groups of 4 blanks, then has a phrase. Each phrase is a concept or a relationship from the CMAP.
#   Example:
#		This
#	    		is
#	        		a sentence
#	            			}
# Output: Replace each empty field with the matching field from the line above, whatever its length. Only output lines ending with "}".
# Example:
#	This is a sentence }
# Optional Postprocessing: Use   grep -v ABC <tn.txt >tn+1.txt  # to eliminate lines containing ABC

BEGIN { FS = " {4}";  prevline[1] = ""} 
 for (i = 1; i < NF; i++) { if (length($i) < 1) $i = prevline[i] } # replace each empty field with the phrase from above, whatever its length.
 for (i = 1; i <= NF; i++) { prevline[i] = $i } # does not handle empty line with 0 tokens; leaves uninteresting content in prevline left over from longer earlier lines 
 # print                                     # prints every line
 if (substr($NF,length($NF)) == "}") print  # prints only lines that end in "}".

Site Admin
Posts: 686
Joined: Sat Dec 13, 2008 2:22 pm

Re: Fill in (DeOutline) what was Exported as Outline

Post by cmapadmin » Mon Apr 23, 2018 10:11 am

Awk, powerful but not appreciated. Thanks for sharing.

Post Reply