How to use certain entries from a txt file as metadata?
So during my plugin development I stumbled on a problem.
I have created a txt file for each picture telling me who's in the photos. So the first column in the file shows all the names that appear in the photo.
I want to add those names into LR for each photo. I thought using them as metadata would be a good idea. Then I could let the user enter a name of some person and create a smart collection having all photos with that person in them.
But putting it into practice isn't that easy.
So I started with the classic metadata definition:
metadataFieldsForPhotos = {
id = 'Person',
title = 'Person'
dataType = 'string',
searchable = true,
browsable = true,
Now I don't know how to actually read only the column entries of the txt file and displaying all the names appearing in it. Another problem is that each photo has its own txt file in "nameofphoto.jpg.txt" So LR must know which txt file belongs to a photo.
I know my question isn't very specific but it would be great if someone could help...
Thank you for the reply. Reading the file how I wanted worked fine and I chose to use keywords, as you suggested.
So now I tried to add the keywords to the pictures and I get:
"LrCatalog:withWriteAccessDo: could not execute action 'keywordProvider'. It was blocked by another write access call, and no timeout parameters were provided."
There's my function so far:
function Finder.findPerson(smartCollectionName)
local catalog = LrApplication.activeCatalog()
local photos = catalog:getMultipleSelectedOrAllPhotos()
LrTasks.startAsyncTask( function()
for i=1,#photos do
local photo = photos[i]
local photopath = photo:getRawMetadata("path")
local photoname = photo:getFormattedMetadata("fileName")
local folderpath = string.sub(photopath, 1, string.len(photopath) - string.len(photoname))
local metadataPath = folderpath .. "\.metaface\\" .. photoname .. ".txt"
local text = LrFileUtils.readFile(metadataPath)
local metadataValues = stringSplit(text)
for i = 0, #metadataValues do
catalog:withWriteAccessDo( "keywordProvider", function()
local keywords = catalog:createKeyword(metadataValues[i])
photos:addKeyword(keywords)
end)
end
end
end)
end
So what am I doing wrong?
Similar Messages
-
How to read Chinese word from a TXT file
File.OpenText() read a TXT File with Chinese word in ;but it not show right.
exam:The TXT File include :中国
this.Txt1.Text=ofd.File.OpenText().ReadToEnd();
but it show :��ʹ�ݼƻ��
How to solve itWhat encoding does the text file use? Unlike .NET, Silverlight only supports UTF-8 and UTF-16. File.OpenText() uses UTF-8 by default.
If the text file is in some other encoding, you can create your own encoding class (that derives from System.Text.Encoding) that can be used to read the text file.
class MyEncoding : System.Text.Encoding {
this.Txt1.Text = (new StreamReader(ofd.File.OpenRead(), new MyEncoding())).ReadToEnd();
Regards,
Justin Van Patten
Program Manager
Common Language Runtime -
How to skip certain lines for a txt file and insert into array
so here is my question:
i had a file to read, and it requires to input into the array starting from a certain line
example:
4
john 25 M
mary 22 F
lee 20 M
faye 10 F
faye john
mary john
mary faye
i want to insert the friend list, starting 5th line into a 2d array, which is the int from first line +1.
can someone help me with it?
i believe there is a skip method and stuff..
but just dont know how to use it
may someone tell me how to do tat?the thing is i think that takes too long and it is not efficient..
however...i just solved it with a better method
Scanner in = new Scanner (reader);
int size = Integer.parseInt(in.next());
BufferedReader insert = new BufferedReader(new FileReader(new File(input)));
String line = null;
int count = 0;
int startAtLineNo =size+1; // 0-based
while ((line = insert.readLine()) != null) {
if (count >= startAtLineNo) {
/* do stuff */
System.out.println(line);
// else ignore
count++;
thanks anyways -
How to read last line from a .txt file?
Hello
I have a string: e.g. "my name is John"
and i wanna verify if this string is equal with the last line from a text file
for example, if in the txt file i have:
asdasd
sdgsdfgasd
asdfgadfgadf
sdgasdgsdf
my name is john
then it's OK.
but if i have
asdgsdfg
dsfhsdfhsd
sdgasdfg
sdgsdg
my name is Jdfgsdg
this is not correct
How should i do this?
Thanks:)Read from the beginning an discard all lines (if you have a small file), or use RandomAccessFile and scan from the end till you find the beginning of the last line.
Kaj -
How to read partcicular line from a txt file
in a text file let there be 50 lines
while reading the line if the line is having "name" as a string in that line then i have to store the next two consecutive lines in a string as array....
Similar way and so on......
How can we do this....You need a BufferedReader:
http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedReader.html
for example:try {
BufferedReader br = new BufferedReader(new FileReader("myfile.txt"));
String line;
while ( (line=br.readLine()) != null ) {
if (line.indexOf("name") != -1) {
// Store the next two lines.
// You will need to call br.readLine() again.
} catch (IOException x) {
x.printStackTrace();
} -
How do i remove header from a txt file
Hello. I have an aquisition file and this remove_headers.vi does not remove all my header. I m attaching the file, the remove_header.vi and the file after removeing header.
Pls help.
Thanks a lot...
Solved!
Go to Solution.
Attachments:
file.txt 223 KB
remove_headers.vi 40 KB
file_after1.jpg 231 KBHere you go. You should read as string to get the whole header, then delete the first six rows of the array(as previously mentioned). Finally write it back to a new file.
Regards,
Even
Certified LabVIEW Associate Developer
Automated Test Developer
Topro AS
Norway
Attachments:
remove_headers_mod.vi 12 KB -
How to retrieve IndividualStrings from a txt file using String Tokenizer.
hello can any one help me to retrieve the individual strings from a txt file using string tokenizer or some thing like that.
the data in my txt file looks like this way.
Data1;
abc; cder; efu; frg;
abc1; cder2; efu3; frg4;
Data2
sdfabc; sdfcder; hvhefu; fgfrg;
uhfhabc; gffjcder; yugefu; hhfufrg;
Data3
val1; val2; val3; val4; val5; val6;
val1; val2; val3; val4; val5; val6;
val1; val2; val3; val4; val5; val6;
val1; val2; val3; val4; val5; val6;
i need to read the data as an individual strings and i need to pass those values to diffarent labels,the dat in Data3 i have to read those values and add to an table datamodel as 6 columns and rows depends on the data.
i try to retrieve data using buffered reader and inputstream reader,but only the way i am retrieving data as an big string of entire line ,i tried with stringtokenizer but some how i was failed to retrive the data in a way i want,any help would be appreciated.
Regards,Hmmm... looks like the file format isn't even very consistent... why the semicolon after Data1 but not after Data2 or Data3??
Your algorithm is reading character-by-character, and most of the time it's easier to let a StringTokenizer or StreamTokenizer do the work of lexical analysis and let you focus on the parsing.
I am also going to assume your format is very rigid. E.g. section Data1 will ALWAYS come before section Data2, which will come before section Data3, etc... and you might even make the assumption there can never be a Data4, 5, 6, etc... (this is why its nice to have some exact specification, like a grammar, so you know exactly what is and is not allowed.) I will also assume that the section names will always be the same, namely "DataX" where X is a decimal digit.
I tend to like to use StreamTokenizer for this sort of thing, but the additional power and flexibility it gives comes at the price of a steeper learning curve (and it's a little buggy too). So I will ignore this class and focus on StringTokenizer.
I would suggest something like this general framework:
//make a BufferedReader up here...
do
String line = myBufferedReader.readLine();
if (line!=null && line.trim().length()>0)
line = line.trim();
//do some processing on the line
while (line!=null);So what processing to do inside the if statement?
Well, you can recognize the DataX lines easily enough - just do something like a line.startsWith("Data") and check that the last char is a digit... you can even ignore the digit if you know the sections come in a certain order (simplifying assumptions can simplify the code).
Once you figure out which section you're in, you can parse the succeeding lines appropriately. You might instantiate a StringTokenizer, i.e. StringTokenizer strtok = new StringTokenizer(line, ";, "); and then read out the tokens into some Collection, based on the section #. E.g.
strtok = new StringTokenizer(line, ";, ");
if (sectionNo==0)
//read the tokens into the Labels1 collection
else if (sectionNo==1)
//read the tokens into the Labels2 collection
else //sectionNo must be 2
//create a new line in your table model and populate it with the token values...
}I don't think the delimiters are necessary if you are using end-of-line's as delimiters (which is implicit in the fact that you are reading the text out line-by-line). So the original file format you listed looks fine (except you might want to get rid of that rogue semicolon).
Good luck. -
How to add the entries and how to delete the entries from custom Z-table?
Hi Experts,
My requirement is I need to add the entries from program to three custom z-tables . Assume as zabc1,zabc2,zabc3.
Here how to add the entries from program to Z-table.???
And one more requirement is I want to provide a deletion checkbox in selection screen . Initial it was unchecked. If I am giving tick mark then the entries should be deleted from above custom Z-tables. this all will done in backgroung job?
Could you please guide me the logic how to crack this???
Let me know if you need more Info
Thanks
SanjuHi Sanjana,
What you can do is to use the ABAP keyword INSERT or MODIFY to add or modify records to a given database table. Here are the syntax taken from SAP documentation:
*Insert Statement
INSERT dbtab
Syntax
INSERT { {INTO target VALUES source }
| { target FROM source } }.
Effect
The INSERT statement inserts one or more rows specified in source in the database table specified in target. The two variants with INTO and VALUES or without INTO with FROM behave identically, with the exception that you cannot specify any internal tables in source after VALUES.
System Fields
The INSERT statement sets the values of the system fields sy-subrc and sy-dbcnt.
sy-subrc Meaning
0 At least one row was inserted.
4 At least one row could not be inserted, because the database table already contains a row with the same primary key or a unique secondary index.
The INSERT statement sets sy-dbcnt to the number of rows inserted.
Note
The inserted rows are finally included in the table in the next database commit. Up until this point, they can still be removed by a database rollback.
*Modify Statement
MODIFY dbtab
Syntax
MODIFY target FROM source.
Effect
The MODIFY statement inserts one or several lines specified in source in the database table specified in target, or overwrites existing lines.
System fields
The MODIFY statement sets the values of the sy-subrc and sy-dbcnt system fields.
sy-subrc Meaning
0 At least one line is inserted or changed.
4 At least one line could not be processed since there is already a line with the same unique name secondary index in the database table.
The MODIFY statement sets sy-dbcnt to the number of processed lines.
Note
The changes are transferred finally to the database table with the next database commit. Up to that point, they can be reversed using a database rollback.
Hope it helps...
P.S. Please award points if it helps... -
How to calculate the number of vowels from a txt file. Pls give me a hand!!
Guys! How do i calculate the number of vowels from a txt file? I have to create a program to count the number of words, sentence, and vowels. So far I had managed to count the number of words. Now I need help on counting sentence and vowels! Pls give me a hand guys!
I first have to read from the file not the string.I
know how to read from a file. Now the problem ishow
to compare a character from a txt file!You fail to understand, that you have read the data
from the file into a string. Now loop over all
characters in the string. Forget about the file.
KajOr forget the scanners just as others have told you. Just read the file character by character using a FileReader.
Kaj -
How to use budget amount from previous years
Dear Values Consultant
How to use budget amount from previous years
I create budget for 2007 and I use it .in 2008 I create new budget with new amount for account, but still there are amount from 2007-I want to use or transfer it to 2008,
How to do this? Please give me details step to implement to this feature
Thanks for caringHi,
There are two ways to do it:
1. Define the account range in your Budget Organization and in the Budgetary Control region, out the Amount Type as "PJTD" and Boundary as "Project". This method is useful when you have project as a segment in your chart of accounts and the Budgets are defined for the full project.
2. The Other way is to carry forward your funds available from last year. Go to Journals -> Generate -> Carry Forward and carry forward the balance for a certain range of account from one financial year to the next one.
Gajendra -
How to fill a table with data from columns & rows from a txt file
I am trying to fill say:
Myname Myclass Mycollege
Mohan MD Stanford
from a txt file into 3 columns of a table. I can easily do it into a textarea component by
clicking a button:
try{
FileReader fr = new FileReader("F:/CreatorProjects1/stan.txt");
BufferedReader br = new BufferedReader(fr);
String s1="";
String s="";
stantxtarea.setValue(s);
while((s=br.readLine())!=null) {
s1 = s1+s;
s1=s1+"\n";
stantxtarea.setValue(s1);
br.close();
fr.close();
} catch(Exception e) {
e.printStackTrace();
return null;
All table components seem to need a database. I do not use any database. I run exe files that give output to txt files. How to solve it?
I appreciate any help in this regard...
dr.mohan raothere may be another way. This is some thing some thing I can recommend. You can create property type of ObjectListDataProvider in session or application based on the scope you required. Create web bean class with property you want to show in the column (say col1, col2, col2). Initialize the list property like similar below
List dataList = new ArrayList();
ObjectListDataProvider mytableprops = new ObjectListDataProvider();
try {
//start loop read data from your txt file
//create instance of web bean for each line
//add web bean instance into dataList
//end of loop readind data from txt file
oldpins.setList(dataList );
oldpins.setObjectType(NotificationProfileBean.class);
} catch (Exception ee1){;}
return oldpins;
Sri Thuraisamy -
How to skip footer details when loading data from a .txt file
Hello experts,
i have to import data from a txt file into my database. I have skipped my header info by using SKIP but how can i ignore my footer details.
ThanksReply on your other thread:
Processing txt file for a required format -
Help, how to check anonymous entry from access logfile.
Can someone tell me how to check anonymous entry from logfile?
From which field I can tell it's an anonymous entry?
Thanks!
MarvinIn the Directory's access log you will see a RESULT entry like the following, where the dn="" indicates an anonymous BIND
[01/Mar/2007:14:24:59 -0500] conn=7 op=0 msgId=1 - RESULT err=0 tag=97 nentries=0 etime=0.127000 dn=""
If an actual user logged in the RESULT line would include the user's DN, like below
[01/Mar/2007:14:24:59 -0500] conn=2019877 op=0 msgId=1 - RESULT err=0 tag=97 nentries=0 etime=0.127000 dn="uid=myuserid,ou=people,dc=test,dc=com"
If you are deloyed on a Unix/Linux system you can count all the anonymouse BINDS using the following
grep -c "tag=97 .*dn=\"\"" access -
How can I print stuff from the 'Help' file using my MacBook Air?
How can I print stuff from the 'Help' file using my MacBook Air?
Open the Help viewer, select a category then from the menu bar top of your screen, click File > Print
-
How to use Connection Pool in ADF ear file creaion from jDev 10.1.3
Hi,
We are developing big application in ADF with 10 different modules. We are creating ear file with data source setting.
How to use connection pool while creating ear file from jDev. Connection pool is alreday created in Application Server 10g.
What all the setting we need do to make use of connection pool while creating ear file jDev.
ThanksUser,
If you are using ADF Business Components, you can right-click each application module, select "configurations" and edit the configuration you are using. On the initial page of the configuration dialog, you can specify to use either a JDBC URL or a Datasource - you just need to choose Datasource and then provide the name by which to access it.
John
Maybe you are looking for
-
How can I manually direct the path I want into my PC folders???
on my laptop, my company has what's called a "Personal Profile" for me. I have a limited profile space that I can take up. My Personal Profile space is everything in "My Documents" PLUS everything in my "Application Data". When I exceed this "profile
-
When my phone is not plugged into the charger or computer, it will not turn on at all; even though it is not dead. When it's plugged into the computer, it will go to a white screen with a grey apple icon and then it will turn off again and repeat. IO
-
SDO_Relate and SDO_filter with SDO_Join
Hi all, Could someone please help me in finding the difference with the below query I am comparing SDO_Relate and SDO_filter with SDO_join. Query using SDO_Relate and SDO_filter SELECT count(spa1.id) FROM temp_tab tmp_tab, spatial_tab spa1, spatial_t
-
Hi, after taking two images of a landscape, one exposed for the foreground and another exposed for the sky. How do I open them each in a seperate layer so I can blend the two together. Giving me a correctly exposed image of foreground and sky. I dont
-
Moved to new TM disk, now no history available
Hello, I recently had to move my Time Machine backups from one external drive to another. The new drive connects to my MacBook Pro just fine, and the Time Machine prefpane correctly identifies the oldest and newest backups and will make new increment