Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting unique values 2

Status
Not open for further replies.

jinkys

Programmer
Sep 11, 2003
67
GB
Hi there

Any give me a hint how to extract unique valies from a series?

e.g. 12234455677

From this series I would only want 1 3 and 6 as they only have one entry

Any help much appreciated
 
ok here is an answer. Type tree and map exports included (6.7.1).
Copy and import type tree and maps.
Input string is a group of single recurring characters. It passes each character and the string to a second map and uses countstring = 1 to return single occurrence characters.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE TTMAKER SYSTEM "ttmaker60.dtd">
<?ANALYZE?><TTMAKER Version="6.0"><NEWTREE Filename="C:\TypeTrees\OKFile.mtt"><ROOT SimpleTypeName="Root" SetUpProperties="DEFAULT" SetUpComponents="DELETE" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/></Sequence>
<CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</ROOT>
<CATEGORY SimpleTypeName="File" CategoryParent="Root" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/></Sequence>
<CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</CATEGORY>
<GROUP SimpleTypeName="OKFile" CategoryOrGroupParent="File Root" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/><SequenceComponent><RelativeTypeName>OKRecord Record</RelativeTypeName>
<Range Min="0" Max="S"/>
</SequenceComponent>
</Sequence>
</GROUP>
<CATEGORY SimpleTypeName="Items" CategoryParent="Root" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/></Sequence>
<CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</CATEGORY>
<ITEM SimpleTypeName="OKItem" CategoryOrItemParent="Items Root" partition="NO" OrderSubtypes="ASCENDING"><CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</ITEM>
<CATEGORY SimpleTypeName="Record" CategoryParent="Root" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/></Sequence>
<CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</CATEGORY>
<GROUP SimpleTypeName="OKRecord" CategoryOrGroupParent="Record Root" OrderSubtypes="ASCENDING"><TypeSyntax><TERMINATOR><Literal IgnoreCase="NO"><Western CharSet="NATIVE"/>
<LiteralValue>&lt;CR&gt;&lt;LF&gt;</LiteralValue>
</Literal>
</TERMINATOR>
</TypeSyntax>
<Sequence partition="NO"><Implicit/><SequenceComponent><RelativeTypeName>OKItem Items</RelativeTypeName>
<Range Min="1" Max="1"/>
</SequenceComponent>
</Sequence>
</GROUP>
</NEWTREE>
</TTMAKER>
 
Hi Janhes

Thank for your response, I have managed to import the map but I am struggling to import type trees, how exactly do yuo do thias?
 
Hi Janhes

Managed to get it working but output is below ?????

3
3
3
3
3
3
3
3
3
3
3
3
3

 
Ah, that's not what mine gave. Are you using 6.7.1?
I input 1223444566777 and it output
1
3
5
It's easy enough to output them as a string. Just get rid of the <CF><LF> terminator on the output record.
 
Are you looking for a unique value within a text string or a unique value in a set of elements or group iee

string:
1111223444556

common elements:
1
1
1
2
2
3
4
4
4
5
5

If the first janhes's sugestion should work. If second try
=unique(set of elements/fields with unique value)
 
Oops. I red flagged one of my duplicate entries but the map seems to have been deleted as well.
Here it is again plus the missing type tree for the output card
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MMS SYSTEM "mms.dtd">
<MMS mapcount="3" path="C:\TEMP\uniquestring2.mms">

 <Map name="getstring" InputCount="1" OutputCount="1" AuditCount="0" RemarkCount="0">
  <MapSettings>
   <MapAudit Switch="ON">
    <BurstAudit>
     <Data.Never SizeValidation="WrongSize"/>
     <Execution.Never/>
    </BurstAudit>
    <SummaryAudit execution="Always"/>
    <SettingsAudit data="Never" map="Never"/>
    <AuditLocation.File>
     <Directory.Custom>Logs\</Directory.Custom>
     <FileName.Unique/>
    </AuditLocation.File>
   </MapAudit>
   <MapTrace Switch="ON">
    <ContentTrace.File Switch="ON">
     <TraceLocation.File>
      <Directory.Custom>Trace\</Directory.Custom>
      <FileName.Default/>
     </TraceLocation.File>
     <InputContentTrace.ALL/>
     <RulesTrace.ALL/>
     <SummaryContentTrace.ON/>
    </ContentTrace.File>
   </MapTrace>
   <WorkSpace.File PageSize="64" PageCount="8">
    <Directory.Map/>
    <WorkFilePrefix.MapName action="Delete"/>
   </WorkSpace.File>
   <Century.Current/>
   <Validation.Standard/>
   <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
   <Warnings.Every action="warn"/>
  </MapSettings>

  <Input>
    <Schema cardnumber="1"
            cardname="stringin"
            typetree="..\TypeTrees\string.mtt"
            type="stringofchars stringtest"/>
    <SourceRule>
      <FetchAs>
       <Integral workarea="Create" fetchunit="S"/>
      </FetchAs>
      <GET>
       <FILE_Source>
        <FilePath>stringin.txt</FilePath>
        <FILE_Source.Transaction OnSuccess="Keep" OnFailure="Rollback" Scope="Map"/>
        <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
        <DocumentVerification>Never</DocumentVerification>
       </FILE_Source>
      </GET>
      <Backup Switch="OFF" When="Always">
       <BackupLocation.File>
        <Directory.Map/>
        <FileName.Custom action="Create"></FileName.Custom>
       </BackupLocation.File>
      </Backup>
    </SourceRule>
  </Input>

  <Output>
    <Schema cardnumber="1"
            cardname="results"
            typetree="..\TypeTrees\OKFile.mtt"
            type="OKFile File Root"/>
    <TargetRule>
      <PUT>
       <FILE_Target>
        <FilePath>resultsout.txt</FilePath>
        <FILE_Target.Transaction OnSuccess="Create" OnFailure="Rollback" Scope="Map"/>
        <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
        <DocumentVerification>Never</DocumentVerification>
       </FILE_Target>
      </PUT>
      <Backup Switch="OFF" When="Always">
       <BackupLocation.File>
        <Directory.Map/>
        <FileName.Custom action="Create"></FileName.Custom>
       </BackupLocation.File>
      </Backup>
    </TargetRule>
    <MapRule rulenumber="1">
      <objectset>OKRecord Record:results</objectset>
      <objectrule>=f_find_unique(character:stringin,stringin)</objectrule>
    </MapRule>
  </Output>
</Map>

 <Map name="f_find_unique" InputCount="2" OutputCount="1" AuditCount="0" RemarkCount="0">
  <MapSettings>
   <MapAudit Switch="ON">
    <BurstAudit>
     <Data.Never SizeValidation="WrongSize"/>
     <Execution.Never/>
    </BurstAudit>
    <SummaryAudit execution="Always"/>
    <SettingsAudit data="Never" map="Never"/>
    <AuditLocation.File>
     <Directory.Custom>Logs\</Directory.Custom>
     <FileName.Default action="Create"/>
    </AuditLocation.File>
   </MapAudit>
   <MapTrace Switch="ON">
    <ContentTrace.File Switch="ON">
     <TraceLocation.File>
      <Directory.Custom>Trace\</Directory.Custom>
      <FileName.Default/>
     </TraceLocation.File>
     <InputContentTrace.ALL/>
     <RulesTrace.ALL/>
     <SummaryContentTrace.ON/>
    </ContentTrace.File>
   </MapTrace>
   <WorkSpace.File PageSize="64" PageCount="8">
    <Directory.Map/>
    <WorkFilePrefix.MapName action="Delete"/>
   </WorkSpace.File>
   <Century.Current/>
   <Validation.Standard/>
   <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
   <Warnings.Every action="warn"/>
  </MapSettings>

  <Input>
    <Schema cardnumber="1"
            cardname="In1"
            typetree="..\TypeTrees\string.mtt"
            type="character stringtest"/>
    <SourceRule>
      <FetchAs>
       <Integral workarea="Create" fetchunit="S"/>
      </FetchAs>
      <GET>
       <FILE_Source>
        <FILE_Source.Transaction OnSuccess="Keep" OnFailure="Rollback" Scope="Map"/>
        <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
        <DocumentVerification>Never</DocumentVerification>
       </FILE_Source>
      </GET>
      <Backup Switch="OFF" When="Always">
       <BackupLocation.File>
        <Directory.Map/>
        <FileName.Custom action="Create"></FileName.Custom>
       </BackupLocation.File>
      </Backup>
    </SourceRule>
  </Input>

  <Input>
    <Schema cardnumber="2"
            cardname="In2"
            typetree="..\TypeTrees\string.mtt"
            type="stringofchars stringtest"/>
    <SourceRule>
      <FetchAs>
       <Integral workarea="Create" fetchunit="S"/>
      </FetchAs>
      <GET>
       <FILE_Source>
        <FILE_Source.Transaction OnSuccess="Keep" OnFailure="Rollback" Scope="Map"/>
        <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
        <DocumentVerification>Never</DocumentVerification>
       </FILE_Source>
      </GET>
      <Backup Switch="OFF" When="Always">
       <BackupLocation.File>
        <Directory.Map/>
        <FileName.Custom action="Create"></FileName.Custom>
       </BackupLocation.File>
      </Backup>
    </SourceRule>
  </Input>

  <Output>
    <Schema cardnumber="1"
            cardname="Out"
            typetree="..\TypeTrees\OKFile.mtt"
            type="OKRecord Record Root"/>
    <TargetRule>
      <PUT>
       <FILE_Target>
        <FILE_Target.Transaction OnSuccess="Create" OnFailure="Rollback" Scope="Map"/>
        <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
        <DocumentVerification>Never</DocumentVerification>
       </FILE_Target>
      </PUT>
      <Backup Switch="OFF" When="Always">
       <BackupLocation.File>
        <Directory.Map/>
        <FileName.Custom action="Create"></FileName.Custom>
       </BackupLocation.File>
      </Backup>
    </TargetRule>
    <MapRule rulenumber="1">
      <objectset>OKItem Items:Out</objectset>
      <objectrule>=run(&quot;findunique&quot;,(echoin(1,In1) + echoin(2,text(In2)) + &quot; -OE1&quot;))</objectrule>
    </MapRule>
  </Output>
</Map>

 <Map name="findunique" InputCount="2" OutputCount="1" AuditCount="0" RemarkCount="0">
  <MapSettings>
   <MapAudit Switch="ON">
    <BurstAudit>
     <Data.Never SizeValidation="WrongSize"/>
     <Execution.Never/>
    </BurstAudit>
    <SummaryAudit execution="Always"/>
    <SettingsAudit data="Never" map="Never"/>
    <AuditLocation.File>
     <Directory.Custom>Logs\</Directory.Custom>
     <FileName.Unique/>
    </AuditLocation.File>
   </MapAudit>
   <MapTrace Switch="ON">
    <ContentTrace.File Switch="ON">
     <TraceLocation.File>
      <Directory.Custom>Trace\</Directory.Custom>
      <FileName.Default/>
     </TraceLocation.File>
     <InputContentTrace.ALL/>
     <RulesTrace.ALL/>
     <SummaryContentTrace.ON/>
    </ContentTrace.File>
   </MapTrace>
   <WorkSpace.File PageSize="64" PageCount="8">
    <Directory.Map/>
    <WorkFilePrefix.MapName action="Delete"/>
   </WorkSpace.File>
   <Century.Current/>
   <Validation.Standard/>
   <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
   <Warnings.Every action="warn"/>
  </MapSettings>

  <Input>
    <Schema cardnumber="1"
            cardname="character"
            typetree="..\TypeTrees\string.mtt"
            type="character stringtest"/>
    <SourceRule>
      <FetchAs>
       <Integral workarea="Create" fetchunit="S"/>
      </FetchAs>
      <GET>
       <FILE_Source>
        <FilePath>b</FilePath>
        <FILE_Source.Transaction OnSuccess="Keep" OnFailure="Rollback" Scope="Map"/>
        <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
        <DocumentVerification>Never</DocumentVerification>
       </FILE_Source>
      </GET>
      <Backup Switch="OFF" When="Always">
       <BackupLocation.File>
        <Directory.Map/>
        <FileName.Custom action="Create"></FileName.Custom>
       </BackupLocation.File>
      </Backup>
    </SourceRule>
  </Input>

  <Input>
    <Schema cardnumber="2"
            cardname="string"
            typetree="..\TypeTrees\string.mtt"
            type="stringofchars stringtest"/>
    <SourceRule>
      <FetchAs>
       <Integral workarea="Create" fetchunit="S"/>
      </FetchAs>
      <GET>
       <FILE_Source>
        <FilePath>b</FilePath>
        <FILE_Source.Transaction OnSuccess="Keep" OnFailure="Rollback" Scope="Map"/>
        <Retry Switch="OFF" MaxAttempts="0" Interval="0"/>
        <DocumentVerification>Never</DocumentVerification>
       </FILE_Source>
      </GET>
      <Backup Switch="OFF" When="Always">
       <BackupLocation.File>
        <Directory.Map/>
        <FileName.Custom action="Create"></FileName.Custom>
       </BackupLocation.File>
      </Backup>
    </SourceRule>
  </Input>

  <Output>
    <Schema cardnumber="1"
            cardname="characterout"
            typetree="..\TypeTrees\string.mtt"
            type="character stringtest"/>
    <TargetRule>
      <PUT>
       <SINK_Target>
        <SINK_Target.Transaction OnSuccess="Create" OnFailure="Rollback" Scope="Map" Warnings="Ignore"/>
        <DocumentVerification>Never</DocumentVerification>
       </SINK_Target>
      </PUT>
      <Backup Switch="OFF" When="Always">
       <BackupLocation.File>
        <Directory.Map/>
        <FileName.Custom action="Create"></FileName.Custom>
       </BackupLocation.File>
      </Backup>
    </TargetRule>
    <MapRule rulenumber="1">
      <objectset>characterout</objectset>
      <objectrule>=if(countstring(text(string),character) = 1,character,none)</objectrule>
    </MapRule>
  </Output>
</Map>

</MMS>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE TTMAKER SYSTEM "ttmaker60.dtd">
<?ANALYZE?><TTMAKER Version="6.0"><NEWTREE Filename="C:\TypeTrees\OKFile.mtt"><ROOT SimpleTypeName="Root" SetUpProperties="DEFAULT" SetUpComponents="DELETE" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/></Sequence>
<CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</ROOT>
<CATEGORY SimpleTypeName="File" CategoryParent="Root" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/></Sequence>
<CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</CATEGORY>
<GROUP SimpleTypeName="OKFile" CategoryOrGroupParent="File Root" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/><SequenceComponent><RelativeTypeName>OKRecord Record</RelativeTypeName>
<Range Min="0" Max="S"/>
</SequenceComponent>
</Sequence>
</GROUP>
<CATEGORY SimpleTypeName="Items" CategoryParent="Root" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/></Sequence>
<CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</CATEGORY>
<ITEM SimpleTypeName="OKItem" CategoryOrItemParent="Items Root" partition="NO" OrderSubtypes="ASCENDING"><CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</ITEM>
<CATEGORY SimpleTypeName="Record" CategoryParent="Root" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/></Sequence>
<CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</CATEGORY>
<GROUP SimpleTypeName="OKRecord" CategoryOrGroupParent="Record Root" OrderSubtypes="ASCENDING"><TypeSyntax><TERMINATOR><Literal IgnoreCase="NO"><Western CharSet="NATIVE"/>
<LiteralValue>&lt;CR&gt;&lt;LF&gt;</LiteralValue>
</Literal>
</TERMINATOR>
</TypeSyntax>
<Sequence partition="NO"><Implicit/><SequenceComponent><RelativeTypeName>OKItem Items</RelativeTypeName>
<Range Min="1" Max="1"/>
</SequenceComponent>
</Sequence>
</GROUP>
</NEWTREE>
</TTMAKER>
 
Input typetree was missing as well.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE TTMAKER SYSTEM "ttmaker60.dtd">
<?ANALYZE?><TTMAKER Version="6.0"><NEWTREE Filename="C:\TypeTrees\string.mtt"><ROOT SimpleTypeName="stringtest" SetUpProperties="DEFAULT" SetUpComponents="DELETE" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/></Sequence>
<CharTextWestern><Size Min="0" Max="S"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</ROOT>
<ITEM SimpleTypeName="character" CategoryOrItemParent="stringtest" partition="NO" OrderSubtypes="ASCENDING"><CharTextWestern><Size Min="1" Max="1"/>
<Western CharSet="NATIVE"/>
<ValueRestrictions IgnoreCase="NO" Rule="INCLUDE"></ValueRestrictions>
</CharTextWestern>
</ITEM>
<GROUP SimpleTypeName="stringofchars" CategoryOrGroupParent="stringtest" OrderSubtypes="ASCENDING"><Sequence partition="NO"><Implicit/><SequenceComponent><RelativeTypeName>character</RelativeTypeName>
<Range Min="1" Max="S"/>
</SequenceComponent>
</Sequence>
</GROUP>
</NEWTREE>
</TTMAKER>
 
Hi Janhes

Thanks for trying but now I get an empty output, you've given me a few ideas though.
 
I got the result 136.

Just created small sample tree with One group and multiple items.

Root
-Field
-Group
|_Fields(s)

Use the same tree for input and output in map.

While mapping:

Field:= IF(COUNTSTRING(SERIESTOTEXT(input),Feild:input) = 1, Feild:input,NONE)

Input file:12234455677
Output result: 136




 
Yes that's what I did but used a seond map for the rule
if(countstring(text(string),character) = 1,character,none)

Run map getstring which runs findunique using above rule.
 
Hi Janhes

Thanks for your help aswell then. Just one thing though, why didn't you just write that rule
 
Thought the map would be useful to show how it was used.
You just can't win.
 
Field:= IF(COUNTSTRING(SERIESTOTEXT(input),Field:input) = 1, Field:input,NONE)

Following on from above, I need to pass the output of this to a functional map

=F_Exchange2(EXTRACT(exchange Element, MEMBER( exchangeID, <Output from above>)))

Can anyone think of a way to pass these values so it will run functional map for all inputs ( MEMBER maybe the wrong way)

I can get to work hard coding as below, but I need to pass in from lookup

F_Exchange2(EXTRACT(exchange Element, MEMBER( exchangeID, {"1","3","6")}))

 
Get the result in a previous card and use that result for the functional map.
 
Hi janhes

Not sure I understand what your saying, can you expand a bit?
 
Have an output card (Out1) to do the
Field:=IF(COUNTSTRING(SERIESTOTEXT(input),Field:input) = 1, Field:input,NONE)

and in the next card

=F_Exchange2(EXTRACT(exchange Element, MEMBER( exchangeID, Out1)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top