converting 3-d text into 2-d file text - text

I am having a 512*512 types of file its a x*y type of file . now we are having 512 files of this type . these 512 files are like the z-axis if we have 100 files of this type then our total vertices are 512*512*100 , in this way I have to read a file is there any algorithm to read files arranged this type and putting into a single 2-d text file.
2-d text file will be like this
000 001 010 011 100 101 110 111 ,in this way we go on printing from the 3-d text file into a single 2-d text file
Is there any way to do that if anyone know please let me know that. any tutorial or any code
Sudhanshu
p.s : if you need any other information about my question you tell me.

Okay, I'm going to parse it this way:
You have some files of Type XY:
Each one has a 512*512 table.
You have Z of these files.
You want to turn it into a new type of file, with a 512*512*512 table.
I'll assume that:
You know how to perform basic file I/O.
You know how to parse your existing file (it has a known delimiter for row/column).
It's surprisingly easy: concatenate the files. You know the length, so you know that every 2^18 entries (or 2^9 rows) represents a X-Y plane at an integer Z-location.
If you're worried about the size changing, then go ahead and choose a new delimiter to represent a new Z-index.

Related

Long sentence shortener to generate a readable file name

I'm looking for a way to shorten a sentence (a text of few lines) to produce a "readable" (not too long) file name.
The application scenario is a chatbot where user can submit a media, say a video, with some paired description text (a caption). The application would assign to the video a readable file name, to retrieve afterward the video by his file name.
Imagine a video paired with a more or less long text description of the scene, like by example:
const videoDescription = 'beautiful yellow flowers on foreground, with a background with countryside meadows and many cows'
How could I shorten the description above with a "suitable" short file name?
Ok, I could just give the sentence as a name, maybe something a bit sanitized, like:
const videoFileName = 'beautiful_yellow_flowers_on_foreground_with_a_background_with_countryside_meadows_and_many_cows.MP4'
but in that way I could exceed the 255 limit of file name size (e.g. on Linux)
Any idea for a shortener algo?
Maybe I could build the shortened filename with word abbreviations?
Maybe I could remove from sentence articles, prepositions, etc.?
BTW, a minor issue: I'm working with Italian language, so a bit of chars sanitize is required to produce good filenames.
Last but not least, I'd looking for JavaScript/Node.js code
You can check if the length is larger than 255 and shorten if necessary. You should also check for duplicates and append -1, -2 and so on if necessary.
let filename='some_flowers_on_foreground_with_a_background_with_countryside_meadows_and_few_cows.MP4'
if(filename.length>255)
filename=filename.slice(0,255-4)+'.MP4'

Reading values from a file and outputting each number, largest/smallest numbers, sum, and average of numbers from the file

The issue that I am having is that I am able to read the information from the files, but when I try to convert them from a string to an integer, I get an error. I also have issues where the min/max prints as the entire file's contents.
I have tried using if/then statements as well as using different variables for each line in the file.
file=input("Which file do you want to get the data from?")
f=open('data3.txt','r')
sent='-999'
line=f.readline().rstrip('\n')
while len(line)>0:
lines=f.read().strip('\n')
value=int(lines)
if value>value:
max=value
print(max)
else:
min=value
print(min)
total=sum(lines)
print(total)
I expect the code to find the min/max of the numbers in the file as well as the sum and average of the numbers in the file. The results from the file being processed in the code, then have to be written to a different file. My results have consisted in various errors reading that Python is unable to convert from a str to an int as well as printing the entire file's contents instead of the expected results.
does the following work?
lines = list(open('fileToRead.txt'))
intLines = [int(i) for i in lines]
maxValue = max(intLines)
minvalue = min(intLines)
sumValue = sum(intLines)
print("MaxValue : {0}".format( maxValue))
print("MinValue : {0}".format(minvalue))
print("Sum : {0}".format(sumValue))
print("Avergae : {0}".format(sumValue/len(intLines)))
and this is how my filesToRead.txt is formulated (just a simple one, in fact)
10
20
30
40
5
1
I am reading file contents into a list. Then I create a new list (it can be joined with the previous step as part of some code refactoring) which has all the list of ints.Once when I have the list of ints, its easier to calculate max and min on it.
Note that some of the variables are not named properly. Also reading the whole file in one go (like what I have done here) might be a bad idea if the file is too large. In that case, you should never ever read the whole file in one go. In this case , you need to read it line by line, parse the ints and add them to a list of ints. Once when you are done reading the file, close the file. You can then start your calculations based on the list of ints that you have now obtained.
Please let me know if this resolves your query.
Thanks

Skip element in BizTalk flat file assembly?

I've been tasked to map an input xml (actually an SAP idoc xml), and to generate a number of flat files. Each input xml may yield multiple output files (one output file per lot number), so I will be using xsl:key and the key() function in my mapping, based on the lot number
The thing is, the lot number itself will not be in the file itself, but the output file name needs to contain that lot number value.
So the question really is: can I map the lot number to the xml and have the flat file assembler skip it when it produces the file? Or is there another way the lot number can be applied as file name by the assembly without having it inside the file itself?
In your orchestration you can set a context property for each output message:
msgOutput(FILE.ReceivedFileName) = "DynamicStuff";
msgOutput then goes to the send shape.
In your send port you set the output file like this:
FixedStuff_%SourceFileName%.xml
The result:
FixedStuff_DynamicStuff.xml
If the value is not required in the message content, don't map it. That's it.
To insert at value in the file name, lot number in this case, you will need to promote that value to the FILE.ReceivedFileName Context Property. Then, you can use the %SourceFileName% Macro as part of the name setting in the Send Port. You can set FILE.ReceivedFileName by either Property Promotion or xpath() in an Orchestration.
Bonus: Sorting and Grouping in xslt is rather unwieldy, which is why I don't do that anymore. Instead, you can use SQL: BizTalk: Sorting and Grouping Flat File Data In SQL Instead of XSL

Complex Flat file, is this even possible to do with a Flat file schema in BTS2013R2?

I have been given the task to create an integration between a customers system and an internal system. The customer sends a flat file which I have a hard time getting my head around how to parse using a Flat file schema.
The structure is like this:
H[n] (either H1, H2 or H3)
K3 (0..unbounded)
K4 (0..unbounded)
M4 (0..unbounded)
M5 (0..unbounded)
S4 (0..unbounded)
S5 (0..unbounded)
Each of the lines ends with a normal CR/LF and each line is position based.
Example:
H1 0123 TEST L5A3
K3 20160608 1103 0004
K4 XA TEST 01
M41123 AQ
M5SA
M5X1
S4SENDOUT
S5POP
H1Q 0342 TEST2 KY
S4IN
H3A 1408 TESTING S6T2
M43308 BB
H2 1331 TEST3 SA
S4PO
This should generate 4 XML-nodes in the end, but my primary concern is how to be able to create a schema that could actually interpret this, either using the Flat File Schema Wizard or simply using a Flat File Schema.
Is this even feasible (considering the various line types, message lengths etc)?
I don't see why BizTalk would have a hard time parsing this flat file. Your lines are clearly identified with the two first characters. You can use this as a tag identifier for the record.
I think it's quite a typical example for a structured, positional flat file with repeating records.
This example might give you some indication as to how to do this, it is somewhat similar:
Flat File Schema creation with Tag Identifiers in the input flat file repeating in a random fashion.
In your situation you would have to create the flat file schema using the flat file wizard. Speaking mostly from my own experience, you never get it perfectly correct, so some tweaking of the FF XSD might be necessary.
To ultimately get to your result XML, use a mapping to get from your flat file schema to your desired output XML result schema.

Start loop at specific line of text file in groovy

I am using groovy and I am trying to have a text file be altered at specific line, without looping through all of the previous lines. Is there a way to state the line of a text file that you want to wish to alter?
For instance
Text file is:
1
2
3
4
5
6
I would like to say
Line(3) = p
and have it change the text file to:
1
2
p
4
5
6
I DO NOT want to have to do a loop to iterate through the lines to change the value, aka I do not want to use a .eachline {line ->...} method.
Thank you in advance, I really appreciate it!
I dont think you can skip lines and traverse like this. You could do the skip by using the Random Access File in java, but instead of lines you should be specifying the number of bytes.
Try using readLines() on file text. It will store all your lines in a list. To change content at line n, change content at n-1 index on list and then join on list items.
Something like this will do
//We can call this the DefaultFileHandler
lineNumberToModify = 3
textToInsert = "p"
line( lineNumberToModify, textToInsert )
def line(num , text){
list = file.readLines()
list[num - 1] = text
file.setText(list.join("\n"))
}
EDIT: For extremely large files, it is better that you have a custom implementation. May be something on the lines of what Tim Yates had suggested in the comment on your question.
The above readLines() can easily process upto 100000 lines of text within less than a sec. So you can do something like this:
if(file size < 10 MB)
use DefaultFileHandler()
else
use CustomFileHandler()
//CustomFileHandler
- Split the large file into buckets of acceptable size.
- Ex: Bucket 1(1-100000 lines), Bucket 2(100000-200000 lines), etc.
- if (lineNumberToModify falls in bucket range)
insert into line in the bucket
There is no hard and fast rule to define how you implement your CustomFileHandler as it completely depends on the use case scenario. If you need to do the above operation multiple times on the same file, you can choose to do the complete bucket split first, store them in memory and use the buckets for the following operations. Or if it is a one time operation, you can avoid manipulating all the buckets first but deal with only what you need and process the others later on on-demand basis.
And even within the buckets you can define your own intelligence to speed up your job. Say if you want to insert into 99999 line of a bucket with 1-100000 lines, you can exploit groovy's methods and closures to their fullest,
file.readLines().reverse()[1] = "some text"

Resources