Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am not really sure what to call this, but I am looking for a way to have a "template" for my code to go by when searching for text.

I am working on a project where a summary for a piece of text is supplied to the user. I want to allow the user to select a piece of text on the page so that the next time they come across a similar page I can find the text.

For instance, lets say somebody goes to foxnews.com and selects the article like in the image below. Then whenever they go to any other foxnews.com article I would be able to identify the text for the article and summarize it for them.

Foxnews text selection

But an issue I see with this is for a site like Stack Exchange where you have multiple comments to be selected (like below) which means that I would have to be able to recursively search for all separate pieces of text.

Stack Exchange text selection

Requirements

  • Be able to keep pieces of text separate from each other.

Possible Issues

  • DIV's may not contain ids, classes, or names.
  • A piece of text may span across multiple DIVs
  • How to recognize where an old piece of text ends and a new begins.
  • How to store this information for later searching?
share|improve this question
Hmm, a good Firefox addon idea here I think. But I'm a bit confused on what's the main Question here. – Adel Feb 21 '12 at 18:43
1  
Thanks, I have some other ideas for the extension/addon than just basic summaries. My question is how do I save the "location" of where the text will be. I want to be able to automatically identify the text instead of forcing the user to select the text each time they view a page. I was thinking that some sort of "template/example" system would allow me to find the text easier after following the user's previous selections. – Flipper Feb 21 '12 at 19:29
Have a look at XPath. Anyway, why was this question downvoted? I think it's an interesting question, but it may be better suited to SO? – phant0m Sep 15 '12 at 12:17

closed as not a real question by World Engineer, Matthieu, Jim G., gnat, MainMa Sep 15 '12 at 16:00

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

I am unclear on goal and desired behavior, but this may help If this is a plug-in, I do believe there are standard ways to ascertain the selected start/end locations. (I did something like this a while back.) You should be able to cache the whole string (or key begin/end fragments) for use to find it again later.

You may need to get into div collections / offsets - if users can select across them - that's life - remember them all. I can imagine this being reasonable to implement, but you'd need to develop test cases with real sites right off the bat - looking for the real world complexities.

Watch out for cases where user selection spans an ad - or other dynamic content - that may be different next time.

HTH.

share|improve this answer
You make a good point with the test cases and the dynamic content. But my goal is that when the article points out the text of the article on one webpage, then my script will be able to identify the text of other articles without the user selecting it. Therefore, for every article on that website...the user will never have to select the text, but instead it will automatically be detected for them. Does that make more sense? – Flipper Feb 22 '12 at 3:26
Are you hoping to use the first-time selection to essentially train your software to be able to navigate the HTML structure of a site, focused on article stubs? – codingoutloud Feb 22 '12 at 6:15
Yes, that is exactly what I am looking to do. I want the software to look at the "template" or previously selected text and find the new text through the HTML of the site. – Flipper Feb 22 '12 at 7:06
Is the user responsible for the training "trusted" (an employee perhaps?) or some random person who might or might not do exactly what you like? – codingoutloud Feb 22 '12 at 15:00
Well it will be the user or me. But in general I would like to assume the user. However, there may always be a bad training, but I am ignoring that for now. – Flipper Feb 22 '12 at 17:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.