How do associations, #NS and #NV work in UniData Dictionaries? - dictionary

Does anyone have a quick example of how Associations, #NS and #NV work in UniData?
I’m trying to work out associations in dictionary items but cannot get them to do anything.
For example, in a record
<1,1> = A
<1,2> = B
<2,1> = Apple
<2,2> = Banana
I created 3 dictionary items. LETTER and FRUIT, COMBO as follows
LETTER:
<1> = D
<2> = 1
<3> =
<3> = Letter
<4> = 6L
<5> = M
<6> = COMBO
FRUIT:
<1> = D
<2> = 1
<3> =
<3> = Letter
<4> = 6L
<5> = M
<6> = COMBO
COMBO:
<1> = PH
<2> = LETTER FRUIT
Doing a LIST LETTER FRUIT or LIST COMBO has no difference to when LETTER and FRUIT do not have an association declared in 6.
At this point I thought it might group multivalues together when SELECTing so I created another record as such:
<1,1> = A
<1,2> = B
<2,1> = Banana
<2,2> = Apple
Doing SELECT MyFile WITH LETTER = “A” and FRUIT = “Apple” selects both records, so that cannot be it either.
I then tried changing LETTER to be:
<1> = I
<2> = EXTRACT(#RECORD,1,#NV,1);EXTRACT(FRUIT,1,#NV,1);#1:" (":#2:")" : #NS
<3> =
<3> = Letter
<4> = 6L
<5> = M
<6> = COMBO
Hoping it that a LIST MyFile LETTER would bring back all the different letters with their associated fruit in parentheses. That didn’t work either as now LETTER only ever displayed the first Multivalue instead of all of them. For Eg:
LIST MyFile LETTER 14:05:22 26 FEB 2010 1
MyFile.... LETTER..............
RECORD2 A (Banana)1
RECORD A (Apple)1
2 records listed
The manuals don’t go any further than saying the word “association”. Is anyone able to clarify this for me?

Many times NV and NS only work when using BY-EXP in your LIST or SELECT statements. You need to use modifiers that specifically look at MultiValue and SubValues.
WHEN is one, and BY-EXP is another. There are other, but not sure what they are off the top of my head. I primarly use BY-EXP and BY-EXP-DSND.
LIST MyFile BY-EXP LETTER = "A" BY-EXP FRUIT ="Apple" LETTER FRUIT LETTER.COMBO
To bring back all the combinations, you use need to do the following:
LIST MyFile BY-EXP LETTER LETTER FRUIT LETTER.COMBO
Change the following virtual field from 'LETTER' to say 'LETTER.COMBO' or something along those lines:
<1> = I
<2> = EXTRACT(#RECORD,1,#NV,1);EXTRACT(FRUIT,1,#NV,1);#1:" (":#2:")" : #NS
<3> =
<3> = Letter
<4> = 6L
<5> = M
<6> = COMBO
Hope that helps.
-Nathan

To answer part of my own question:
Only 'WHEN' is affected by the association, not with. If you turn on UDT.OPTIONS 94 and do
LIST MyFile WHEN LETTER = "A" AND FRUIT="Apple" COMBO
when using my D-Type definition of LETTER, I get
LIST MyFile WHEN LETTER = "A" AND FRUIT="Apple" LETTER FRUIT 16:06:42 26 FEB 2010 1
MyFile.... LETTER.............. FRUIT...............
RECORD A Apple
1 record listed
Which is what one would expect.
To use the WHEN clause you need to be in ECLTYPE U, not P. IT would be helpful if this was clearer, but oh well...

Related

Data Scraping with list in excel

I have a list in Excel. One code in Column A and another in Column B.
There is a website in which I need to input both the details in two different boxes and it takes to another page.
That page contains certain details which I need to scrape in Excel.
Any help in this?
Ok. Give this a shot:
import pandas as pd
import requests
df = pd.read_excel('C:/test/data.xlsx')
url = 'http://rla.dgft.gov.in:8100/dgft/IecPrint'
results = pd.DataFrame()
for row in df.itertuples():
payload = {
'iec': '%010d' %row[1],
'name':row[2]}
response = requests.post(url, params=payload)
print ('IEC: %010d\tName: %s' %(row[1],row[2]))
try:
dfs = pd.read_html(response.text)
except:
print ('The name Given By you does not match with the data OR you have entered less than three letters')
temp_df = pd.DataFrame([['%010d' %row[1],row[2], 'ERROR']],
columns = ['IEC','Party Name and Address','ERROR'])
results = results.append(temp_df, sort=False).reset_index(drop=True)
continue
generalData = dfs[0]
generalData = generalData.iloc[:,[0,-1]].set_index(generalData.columns[0]).T.reset_index(drop=True)
directorData = dfs[1]
directorData = directorData.iloc[:,[-1]].T.reset_index(drop=True)
directorData.columns = [ 'director_%02d' %(each+1) for each in directorData.columns ]
try:
branchData = dfs[2]
branchData = branchData.iloc[:,[-1]].T.reset_index(drop=True)
branchData.columns = [ 'branch_%02d' %(each+1) for each in branchData.columns ]
except:
branchData = pd.DataFrame()
print ('No Branch Data.')
temp_df = pd.concat([generalData, directorData, branchData], axis=1)
results = results.append(temp_df, sort=False).reset_index(drop=True)
results.to_excel('path.new_file.xlsx', index=False)
Output:
print (results.to_string())
IEC IEC Allotment Date File Number File Date Party Name and Address Phone No e_mail Exporter Type IEC Status Date of Establishment BIN (PAN+Extension) PAN ISSUE DATE PAN ISSUED BY Nature Of Concern Banker Detail director_01 director_02 director_03 branch_01 branch_02 branch_03 branch_04 branch_05 branch_06 branch_07 branch_08 branch_09
0 0305008111 03.05.2005 04/04/131/51473/AM20/ 20.08.2019 NISSAN MOTOR INDIA PVT. LTD. PLOT-1A,SIPCOT IN... 918939917907 shailesh.kumar#rnaipl.com 5 Merchant/Manufacturer Valid IEC 2005-02-07 AACCN0695D FT001 NaN NaN 3 Private Limited STANDARD CHARTERED BANK A/C Type:1 CA A/C No :... HARDEEP SINGH BRAR GURMEL SINGH BRAR HOUSE NO ... JEROME YVES MARIE SAIGOT THIERRY SAIGOT A9/2, ... KOJI KAWAKITA KIHACHI KAWAKITA 3-21-3, NAGATAK... Branch Code:165TH FLOOR ORCHID BUSINESS PARK,S... Branch Code:14NRPDC , WAREHOUSE NO.B -2A,PATAU... Branch Code:12EQUINOX BUSINESS PARK TOWER 3 4T... Branch Code:8GRAND PALLADIUM,5TH FLR.,B WING,,... Branch Code:6TVS LOGISTICS SERVICES LTD.SING,C... Branch Code:2PLOT 1A SIPCOT INDUL PARK,ORAGADA... Branch Code:5BLDG.NO.3 PART,124A,VALLAM A,SRIP... Branch Code:15SURVEY NO. 678 679 680 681 682 6... Branch Code:10INDOSPACE SKCL INDL.PARK,BULD.NO...

Platform Data Extension: how do I parse ROAD_NAME_FCN

I'm using HERE's Platform Data Extension to retrieve road names. However, I don't understand the strings that I'm getting. I suspect they're encoded somehow but I don't know how to decode them.
For example:
ENGBNFDR Dr NNASN"e|fe "de "e|rre "dri|ve "nol|te;NASY"e|fe "de "e|rre;<snip>
If I split them by a "record separator" character, e.g. link_names.split('\x1e') the values look slightly more intelligible, but only slightly. There are still bizarre abbreviations I don't understand, e.g. ENGBN.
The PDE Layers documents can be found here: http://pde.cit.api.here.com/1/doc/content.html?detail=1&app_id=xxx&app_code=yyy
Layers > ROAD_NAME_FC1 > NAMES.
List of all names for this object, in all languages, latin1/pinyin/phonetic transliterations.
For convenience, non-exonym base names are listed first.
Format:
NAMES = NAME1 \u001D NAME2 \u001D NAME3 ...
NAME = NAME_TEXT \u001E TRANSLIT1 ; TRANSLIT2 ; ... \u001E PHONEME1 ; PHONEME2 ; ... NAME_TEXT = LANGUAGE_CODE NAME_TYPE IS_EXONYM text
TRANSLIT = LANGUAGE_CODE text
PHONEME = LANGUAGE_CODE IS_PREFERRED text
LANGUAGE_CODE is a 3 character string
NAME_TYPE is one letter (A = abbreviation, B = base name, E = exonym, K = shortened name, S = synonym)
IS_EXONYM = Y if the name is a translation into another language
IS_PREFERRED = Y if this is the preferred phoneme.
Please note, the delimiters are:
\u001D between languages (NAMES level)
\u001E between name text, transliterations, and phonemes ';' between different transliterations and phonemes of the same name.

is it possible to get a new instance for namedtuple pushed into a dictionary before values are known?

It looks like things are going wrong on line 9 for me. Here I wish to push a new copy of the TagsTable into a dictionary. I'm aware that once a namedtuple field is recorded, it can not be changed. However, results baffle me as it looks like the values do change - when this code exits all entries of mp3_tags[ any of the three dictionary keys ].date are set to the last date of "1999_03_21"
So, two questions:
Is there a way to get a new TagsTable pushed into the dictionary ?
Why doesnt the code fail and not allow the second (and even third) date to be written to the TagsTable.date field (since it seems to be references to the same namedtuple) ? I thought you could not write a second value ?
from collections import namedtuple
2 TagsTable = namedtuple('TagsTable',['title','date','subtitle','artist','summary','length','duration','pub_date'])
3 mp3files = ['42-001.mp3','42-002.mp3','42-003.mp3']
4 dates = ['1999_01_07', '1999_02_14', '1999_03_21']
5
6 mp3_tags = {}
7
8 for mp3file in mp3files:
9 mp3_tags[mp3file] = TagsTable
10
11 for mp3file,date_string in zip(mp3files,dates):
12 mp3_tags[mp3file].date = date_string
13
14 for mp3file in mp3files:
15 print( mp3_tags[mp3file].date )
looks like this is the fix I was looking for:
from collections import namedtuple
mp3files = ['42-001.mp3','42-002.mp3','42-003.mp3']
dates = ['1999_01_07', '1999_02_14', '1999_03_21']
mp3_tags = {}
for mp3file in mp3files:
mp3_tags[mp3file] = namedtuple('TagsTable',['title','date','subtitle','artist','summary','length','duration','pub_date'])
for mp3file,date_string in zip(mp3files,dates):
mp3_tags[mp3file].date = date_string
for mp3file in mp3files:
print( mp3_tags[mp3file].date )

capital letters in firt letter

In python, I want a program that turn the first leter on a word capital letter.
For exemple:
turn "a red apple is sweeter than a green apple" in "A Red Apple is Sweeter Than A Green Apple"
How can I do?
I've tried this:
d = input('insert a quote')
def mydic(d):
dic = {}
for i in d:
palavras = dic.keys()
if i in palavras:
dic[i] += 1
else :
dic[i] = 1
return dic
You could use the title() method.
For example:
sentence = str(input("Insert a quote: ")).title()
print(sentence)
Input: a red apple is sweeter than a green apple
Output: A Red Apple Is Sweeter Than A Green Apple
What you want to do is this:
split the input string into words ie. string.split(' ') splits a given string by spaces, returns a list.
for each word, capitalize the first letter and concatenate onto a bigger string ie. word[:1].upper() + word[1:] this will uppercase the first letter
Add all the words back into a list and return it.

splitting the string that has more than or equal to two white spaces

I have a string. I want to split the string on uneven white spaces. if the white spaces are more or equal to 2 spaces in length than I want them to be in seperate array item, but if there is only one space then I want them to be in same array item so for e.g.
I have this string
1234 This is a Test PASS 1255432 12/21/2016 07:14:11
so when I split the above string, it should be like this
arr(0) = 1234
arr(1) = This is a test ' because it has only one space in between, it there are more or equal to two spaces than I want it to be a seperate item in an array
arr(2) = Pass
arr(3) = 1255432
arr(4) = 12/21/2016
arr(5) = 07:14:1
same thing with below string:
0001 This is a Marketing text_for the students TEST2 468899 12/23/2016 06:23:16
When I split the above string, it should like this:
arr(0)=0001
arr(1) = This is a Marketing text_for the students
arr(2) = Test2
arr(3)=468899
arr(4)=12/23/2016
arr(5) = 06:23:16
Is there any regular expression that can help me to split the string based on spaces, but put together the words if the space is more or equal to 2.
Any help will be greatly appreciated.
This can be done with this regex (\s{0,1}\S+)+ like so:
string text = "0001 This is a Marketing text_for the students TEST2 468899 12/23/2016 06:23:16";
Regex regex = new Regex(#"(\s{0,1}\S+)+");
var matches = regex.Matches("0001 This is a Marketing text_for the students TEST2 468899 12/23/2016 06:23:16").Cast<Match>()
.Select(m => m.Value)
.ToArray();
Console.WriteLine(String.Join( ",", matches));
This is a working java Script snippet of the same thing.
var value = "0001 This is a Marketing text_for the students TEST2 468899 12/23/2016 06:23:16";
var matches = value.match(
new RegExp("(\\s{0,1}\\S+)+", "gi")
);
console.log(matches)
This regex (\s{0,1}\S+)+ works by matching 0 or 1 spaces at the begging of each match with \s{0,1} and then any number of things that aren't a space with \S+ it then matches this whole thing any number of times by containing it in parentheses and using the + operator (...)+, this allows for the string together of single spaces characters.

Resources