d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Please Help Me Write A Program > Paying 500fg
Add Reply New Topic New Poll
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Aug 26 2014 10:44am
Program: "Thought Organizer."

Purpose: Load a .txt and rearranges the text. Outputs the same .txt but organized by tags. (See example.)

Example.txt

i like girls /g [Girls]
wash dishes /do [To-do]
girls are nice /g [Girls]
eat at 7 /r [Reminders]


Output.txt

Girls:
I like girls.
Girls are nice.

To-do.
Wash dishes.

Reminders:
Eat at 7.

I would like that the output capitalizes the first letter and adds a period if there is no period already. Thanks and let me know if need any clarifications.
Member
Posts: 6,192
Joined: Dec 13 2010
Gold: 6,669.99
Aug 26 2014 03:41pm
Which language?
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Aug 27 2014 09:32pm
Quote (ShadowFiend @ Aug 26 2014 02:41pm)
Which language?


python
Member
Posts: 2,105
Joined: Oct 28 2013
Gold: 3,961.00
Aug 28 2014 12:55am
I do not know python. I'm not going to provide code. I'll show you how I'd do it logically.
note: access/pointer/reference are identical terms.

I'm going to value easy of development vs efficiency, sorry.

for each (non whitespace) line grab 2 elements. you can use regex-replace for ease of implementation. grab everything and replace the last 2 words with nothing, or if the rest of the experession does not terminate with a period replace it with '.', throw this into the following.

the last element of the original string goes into a linked list of the following structure: element, access to tasks, element.next. if an element does not exist append it to the list.
insert the first element of the original string into the head of the linked list of tasks, (task, task.next)

now you've input all your data. output time.

for each element in list of task titles print the task title, then
for each element in that task's access, output the task, newline, until element.next is nil. (don't forget your off by 1 error, make sure to print the final task before ending the loop).
You can also modify your task string at output instead of input, it's probably simpler.

do this until you're out of elements in your task list, then move to the next task title and repeat.

make sure you're outputting to a file type NOT the console.

IF this isn't homework, I'll do it though it'll be in Racket (PLT-Scheme, LISP) using tail recursion. LMK via PM if this is the case. Won't have time until tomorrow night though.

Have fun, hope this helps you.


Member
Posts: 649
Joined: May 28 2012
Gold: 14.00
Aug 28 2014 01:39am
Here you go, also sent by PM

Code

#!/usr/bin/python

import sys,re

if len(sys.argv)<3:
print "Please give input filename and output file name"
exit(1)

inputFile = sys.argv[1]
outputFile = sys.argv[2]

inputFile = open(inputFile,'r')
outputFile = open(outputFile,'w')

pattern = '(.*?)\/(.*?) \[(.*?)\]'

tags = {}

for line in inputFile.readlines():
matches = re.findall(pattern,line)
tag = matches[0][2].strip()
todo = matches[0][0].strip().title()
if not todo.endswith('.'):
todo = todo+'.'
if tag not in tags:
tags[tag] = []
tags[tag].append(todo)

inputFile.close()

for t in tags:
outputFile.write(t+':\n')
for d in tags[t]:
outputFile.write(d+'\n')
outputFile.write('\n')

outputFile.close()



Code
xxx:~ mm$ cat Example.txt
i like girls /g [Girls]
wash dishes /do [To-do]
girls are nice /g [Girls]
eat at 7 /r [Reminders]
xxx:~ mm$ ./org.py Example.txt test.txt
xxx:~ mm$ cat test.txt
Reminders:
Eat At 7.

To-do:
Wash Dishes.

Girls:
I Like Girls.
Girls Are Nice.


This post was edited by FCNantes on Aug 28 2014 01:40am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll