d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Information Organizer Python Program
Add Reply New Topic New Poll
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Feb 22 2016 08:19pm
I need this program written to be compiled by online pytho compiler. Can anyone do for me? Will pay fg.

InputFileText:

Quote
/me = Me
/a = Advice
/w = Writing
/p = Productivity
/r = Random
/o = Observations
//(The ability to define any tag. For example, /bog = Boglands)

Emotions flow through and sink me like quick sand and distract me considerably. /me

Fight harder than you believe you can. /a
There are huge forces at play, to create a person. /r
sjfaslkdfjaldsfjaskldfaldsfksdsadf
dsjfadkjfksj

dsfadfj
Asking me to talk about gossip is nearly impossible. /me
Some humans really want to be around other humans. /r
She wants a popular guy, who owns the world. And she wants to own this popular guy. What fantastic power a girl can wield.

Sparkle and spaz.

If you only have a certain set of songs to listen to, presented before you, those are the songs you listen to and grow to love. /o


Stuyvesant: What amazing support they hold for each other. Liking each other is highly necessary. They're a communal group. /o
I am but a stepping stone. To a higher realm. /me


OutputFileText:


Quote
Date: Today's Date.

Me:
Emotions flow through and sink me like quick sand and distract me considerably.
Asking me to talk about gossip is nearly impossible.
I am but a stepping stone. To a higher realm.

Advice:
Fight harder than you believe you can.

Random:
There are huge forces at play, to create a person.
Some humans really want to be around other humans.

Observations:
If you only have a certain set of songs to listen to, presented before you, those are the songs you listen to and grow to love.
Stuyvesant: What amazing support they hold for each other. Liking each other is highly necessary. They're a communal group.



This post was edited by kdog3682 on Feb 22 2016 08:21pm
Member
Posts: 1,178
Joined: Oct 28 2009
Gold: 1,389.00
Feb 25 2016 11:47am
What would the line like
Code

/abc = ABC. /me

do? Would it define a section named "ABC. /me"? Would it make "/abc = ABC" entry in "Me" section?

Do you have full text of the task or only input and output examples?
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Feb 27 2016 02:06pm
Quote (deadNightTiger @ Feb 25 2016 10:47am)
What would the line like
Code
/abc = ABC. /me

do? Would it define a section named "ABC. /me"? Would it make "/abc = ABC" entry in "Me" section?

Do you have full text of the task or only input and output examples?


Just the input and output example. And to your question, yes.


Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Feb 27 2016 10:00pm
offer: 1000fg
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 28 2016 01:20am
You asked for Python, but I did it in C# because reasons.

Code

public class Program
{
static void Main(string[] args)
{
string line;
Tagger tagger = new Tagger();

var sr = new StreamReader("Input.txt");

while((line = sr.ReadLine()) != null)
{
tagger.AddTag(line);
tagger.TagText(line);
}

List<TaggedText> taggedText = tagger.GetTaggedText();

var textSetByTag = taggedText.GroupBy(t => t.Tag);

Console.WriteLine("Date: {0}", DateTime.Today.Date.ToShortDateString());
foreach(var textSet in textSetByTag)
{
Console.WriteLine();
Console.WriteLine("{0}:", textSet.Key.Label);
textSet.ToList().ForEach(t => Console.WriteLine("{0}", t.Text));
}
}
}


Code
public class Tagger
{
private List<Tag> _tags;
private List<TaggedText> _taggedText;

public Tagger()
{
_tags = new List<Tag>();
_taggedText = new List<TaggedText>();
}

public void TagText(string textToTag)
{
string regex = @"^(.*)\s*(/.*)$";

string[] matches = Regex.Split(textToTag, regex).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

if (matches.Length != 2)
return;

//extract tag
string text = matches[0].Trim();
string code = matches[1].Trim();

//check if tag exists
Tag tag = _tags.FirstOrDefault(t => t.Code.Equals(code));

//tag text
if(tag != null)
{
TaggedText taggedText = new TaggedText(tag, text);
_taggedText.Add(taggedText);
}
}

public void AddTag(string tagExpression)
{
string regex = @"^(/.*)\s*=\s*(.*)$";
//extract code and label
string[] matches = Regex.Split(tagExpression, regex).Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();

if (matches.Length != 2)
return;

string code = matches[0].Trim();
string label = matches[1].Trim();

Tag tag = new Tag(code, label);

_tags.Add(tag);
}

public List<TaggedText> GetTaggedText()
{
return new List<TaggedText>(_taggedText);
}

public List<Tag> GetTags()
{
return new List<Tag>(_tags);
}

}


Code
public class TaggedText
{
public TaggedText(Tag tag, string text)
{
if (tag == null)
throw new ArgumentNullException("tag");

Tag = tag;
Text = text;
}

public Tag Tag { get; private set; }
public string Text { get; private set; }
}


Code
public class Tag
{
public Tag(string code, string label)
{
if (string.IsNullOrWhiteSpace(code))
throw new ArgumentException("Code cannot be empty");
if (string.IsNullOrWhiteSpace(label))
throw new ArgumentException("Label cannot be empty");

Code = code;
Label = label;

}

public string Code { get; private set; }
public string Label { get; private set; }
}
Member
Posts: 1,178
Joined: Oct 28 2009
Gold: 1,389.00
Feb 28 2016 10:13pm
Code
import collections
import datetime
import sys

Section = collections.namedtuple('Section', ['tag', 'name', 'lines'])
sections = []

for line in map(str.rstrip, sys.stdin):
if line.startswith("//"):
continue # skip a comment
elif line.startswith("/"): # define new section
tag, name = line.split(" = ")
sections.append(Section(tag, name, []))
else:
for s in sections:
if line.endswith(s.tag):
s.lines.append(line[0:-len(s.tag)])

print("Date: {}".format(datetime.date.today()))
print()
for s in sections:
if s.lines:
print("{}:".format(s.name))
for l in s.lines:
print(l)
print()


tested with python 3.4 and 3.5, lmk if you need other version

This post was edited by deadNightTiger on Feb 28 2016 10:23pm
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Feb 28 2016 10:51pm
Quote (deadNightTiger @ Feb 28 2016 09:13pm)
Code
import collections
import datetime
import sys

Section = collections.namedtuple('Section', ['tag', 'name', 'lines'])
sections = []

for line in map(str.rstrip, sys.stdin):
if line.startswith("//"):
continue # skip a comment
elif line.startswith("/"): # define new section
tag, name = line.split(" = ")
sections.append(Section(tag, name, []))
else:
for s in sections:
if line.endswith(s.tag):
s.lines.append(line[0:-len(s.tag)])

print("Date: {}".format(datetime.date.today()))
print()
for s in sections:
if s.lines:
print("{}:".format(s.name))
for l in s.lines:
print(l)
print()


tested with python 3.4 and 3.5, lmk if you need other version


www.tutorialspoint.com/ - can you load it on this with the example input.txt I posted?
Member
Posts: 1,178
Joined: Oct 28 2009
Gold: 1,389.00
Feb 29 2016 04:46am
goo.gl/AFI1OT
here you go, modified it a bit to read from file instead of standard input
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll