Convert .bib file into a new .acm file - java

I am trying to convert a .bib that can contains x number of article into a ACM file with said x number of ACM notation. I've written a bit of code but would like help with the rest.
The .bib is formatted this way -->
#ARTICLE{
8249726,
author={N. Khlif and A. Masmoudi and F. Kammoun and N. Masmoudi},
journal={IET Image Processing},
title={Secure chaotic dual encryption scheme for H.264/AVC video conferencing protection},
number={1},
year={2018},
volume={12},
pages={42-52},
keywords={adaptive codes;chaotic communication;cryptography;data compression;data protection;variable length codes;video coding;H.264/AVC video conferencing protection;advanced video coding protection;chaos-based crypto-compression scheme;compression ratio;context adaptive variable length coding;decision module;format compliance;inter-prediction encryption;intra-prediction encryption;piecewise linear chaotic maps;pseudorandom bit generators;secure chaotic dual encryption scheme;selective encryption approach;video compression standards},
doi={10.1049/iet-ipr.2017.0022},
ISSN={1751-9659},
month={Dec},
}
#ARTICLE{
8093611,
author={W. Wu and H. Mao and Y. Wang and J. Wang and W. Wang and C. Tian},
journal={IEEE Access},
title={CoolConferencing: Enabling Robust Peer-to-Peer Multi-Party Video Conferencing},
year={2017},
pages={25474-25486},
number={2},
volume={5},
keywords={Internet;peer-to-peer computing;teleconferencing;video communication;CoolConferencing design;MPVC approach;MPVC platform;any-view support;multirate support;optimal video transmission performance;overlay network;realistic network environments;resilient data-driven principle;robust MPVC system;robust peer-to-peer multiparty video conferencing;robust system;state-of-the-art video;Bandwidth;Delays;Internet;Peer-to-peer computing;Receivers;Robustness;Streaming media;Computer networks;peer to peer computing;streaming media},
doi={10.1109/ACCESS.2017.2768798},
ISSN={1751-9659},
month={Dec},
}
Note that the .bib file can have any number of articles, 2 in this case so the .ACM file should have 2 ACM quotation. Also the articles information doesn't have specific line order.
I can't use any library that auto convert.
Here is the code that I have as of now. This code will read each line of 1 latex file and print all the information between { }, and now I need to save each information and then create a method to return the information in ACM format.
public static void main(String[] args) {
List<String> lines = new ArrayList<>();
try {
File myFile = new File("Latex1.bib");
Scanner reader = new Scanner(myFile);
while (reader.hasNextLine()) {
Pattern pattern = Pattern.compile("=\\{([^}]*)");
Matcher matcher = pattern.matcher(reader.nextLine());
if (matcher.find()) {
System.out.println(matcher.group(1));
}
}
} catch (FileNotFoundException e) {
e.getMessage();
}
}
Could you please complete it?

Related

How to read and filter a raw audio file with python?

I got a .raw file from recording, it was written by the write method from the Java class AudioOutputStream (I wrote bytes).
I want to filter this audio file with a Python filter. Here it is the guide I'm using, it filters a list of float numbers (the variable x in the guide).
My problem is the different types, bytes and floats. Is there a way to make this filter work with that .raw audio?
I appreciate any suggestion. Thanks.
I found two useful java classes: DataInputStream and DataOutputStream to write floats for my Python script to use.
First I read float values from the .raw file with the readFloat method which reads 4 bytes as a float.
FileInputStream is = new FileInputStream(inputName);
DataInputStream dis = new DataInputStream(is);
ArrayList<Float> fbuffer = new ArrayList<Float>();
try {
while(dis.available()>0){
float f = dis.readFloat(); //read 4 bytes as float
// this fails if it is not 4x
fbuffer.add(f);
}
} catch (IOException e) {
//nothing happens, there are 1,2 or 3 bytes at the end we are going to ignore
//e.printStackTrace();
}
dis.close();
is.close();
This way I create a file with the float values. This file is read by the python script. Here I use
fin = open('fileWithFloatsName')
floatList = [line.rstrip('\n') for line in fin]
floatList = destringifyList(floatList)
fin.close()
I get the list of floats, perform the filter as in here and get a new list of floats. I write this result in a new file that java is going to read with a Scanner object.
Finally we create a new .raw file and write the floats as bytes with the writeFloat method.
That's all. If someone suggest something better (partially or not), I will appreciate it.

How to set HTTP header in Apache JClouds?

I'm using Apache JClouds to connect to my Openstack Swift installation. I managed to upload and download objects from Swift. However, I failed to see how to upload dynamic large object to Swift.
To upload dynamic large object, I need to upload all segments first, which I can do as usual. Then I need to upload a manifest object to combine them logically. The problem is to tell Swift this is a manifest object, I need to set a special header, which I don't know how to do that using JClouds api.
Here's a dynamic large object example from openstack official website.
The code I'm using:
public static void main(String[] args) throws IOException {
BlobStore blobStore = ContextBuilder.newBuilder("swift").endpoint("http://localhost:8080/auth/v1.0")
.credentials("test:test", "test").buildView(BlobStoreContext.class).getBlobStore();
blobStore.createContainerInLocation(null, "container");
ByteSource segment1 = ByteSource.wrap("foo".getBytes(Charsets.UTF_8));
Blob seg1Blob = blobStore.blobBuilder("/foo/bar/1").payload(segment1).contentLength(segment1.size()).build();
System.out.println(blobStore.putBlob("container", seg1Blob));
ByteSource segment2 = ByteSource.wrap("bar".getBytes(Charsets.UTF_8));
Blob seg2Blob = blobStore.blobBuilder("/foo/bar/2").payload(segment2).contentLength(segment2.size()).build();
System.out.println(blobStore.putBlob("container", seg2Blob));
ByteSource manifest = ByteSource.wrap("".getBytes(Charsets.UTF_8));
// TODO: set manifest header here
Blob manifestBlob = blobStore.blobBuilder("/foo/bar").payload(manifest).contentLength(manifest.size()).build();
System.out.println(blobStore.putBlob("container", manifestBlob));
Blob dloBlob = blobStore.getBlob("container", "/foo/bar");
InputStream input = dloBlob.getPayload().openStream();
while (true) {
int i = input.read();
if (i < 0) {
break;
}
System.out.print((char) i); // should print "foobar"
}
}
The "TODO" part is my problem.
Edited:
I've been pointed out that Jclouds handles large file upload automatically, which is not so useful in our case. In fact, we do not know how large the file will be or when the next segment will arrive at the time we start to upload the first segment. Our api is designed to make client able to upload their files in chunks of their own chosen size and at their own chosen time, and when done, call a 'commit' to make these chunks as a file. So this makes us want to upload the manifest on our own here.
According to #Everett Toews's answer, I've got my code correctly running:
public static void main(String[] args) throws IOException {
CommonSwiftClient swift = ContextBuilder.newBuilder("swift").endpoint("http://localhost:8080/auth/v1.0")
.credentials("test:test", "test").buildApi(CommonSwiftClient.class);
SwiftObject segment1 = swift.newSwiftObject();
segment1.getInfo().setName("foo/bar/1");
segment1.setPayload("foo");
swift.putObject("container", segment1);
SwiftObject segment2 = swift.newSwiftObject();
segment2.getInfo().setName("foo/bar/2");
segment2.setPayload("bar");
swift.putObject("container", segment2);
swift.putObjectManifest("container", "foo/bar2");
SwiftObject dlo = swift.getObject("container", "foo/bar", GetOptions.NONE);
InputStream input = dlo.getPayload().openStream();
while (true) {
int i = input.read();
if (i < 0) {
break;
}
System.out.print((char) i);
}
}
jclouds handles writing the manifest for you. Here are a couple of examples that might help you, UploadLargeObject and largeblob.MainApp.
Try using
Map<String, String> manifestMetadata = ImmutableMap.of(
"X-Object-Manifest", "<container>/<prefix>");
BlobBuilder.userMetadata(manifestMetadata)
If that doesn't work you might have to use the CommonSwiftClient like in CrossOriginResourceSharingContainer.java.

How to extract URL to video from Website Code

I am in the process of making an application that streams anime from sites. However in order to do so, I need the direct link to a video for instance:
http://s1000.animepremium.tv/stream/74017.mp4
However, this site I'm currently trying to stream from animeseason.com, but I cannot find the link to the video from the code.
Here's the code:
Mp4up Player
As you can see the video seems to be encrypted, is it possible to decrypt? If so how would I achieve this?
Thanks in advance!
Edit: I already have a streaming thing set up in java that will work for any video such as the one from the first link. I just need to know how to decrypt the video link from the code above...
Edit2; I am using Java, so if there is already a solution in java please tell me
Challenge accepted if you mean the video URL is encrypted and not the video itself.
And it is not like the video URL is encrypted, it is more like "obfuscated" since the structure of the data is visible. So to de-obfuscate:
public class Q21300109 {
public static final String urlEncoded = "%{3c%-69%$66%X72%!61%F6d%N65%Z20%#6d%[61%W72%J67%#69%U6e%#68%C65%J69%V67%R68%B74%D3d%-22%[30%G22%S20%P6d%A61%M72%~67%Y69%A6e%T77%V69%*64%D74%I68%+3d%R22%[30%Z22%L20%Q73%]63%A72%+6f%X6c%C6c%G69%F6e%U67%H3d%I22%Q6e%C6f%P22%[20%S66%P72%G61%F6d%A65%H62%Y6f%V72%?64%!65%#72%+3d%E22%Y30%X22%Q20%A77%T69%Q64%+74%C68%T3d%D22%H35%?34%L30%Q22%P20%O68%*65%K69%{67%H68%R74%+3d%H22%Z33%W30%#34%Y22%K20%S73%W72%P63%C3d%F22%*68%D74%Y74%H70%A3a%!2f%~2f%E6d%]70%~34%P75%L70%B6c%#6f%D61%M64%W2e%K63%#6f%U6d%R2f%O65%C6d%G62%?65%M64%Z2d%W34%!6b%#68%!71%T66%*7a%M37%~34%{6e%?67%N6a%-6e%[2e%A68%L74%G6d%B6c%B22%J3e%O3c%Y2f%T69%D66%E72%+61%S6d%H65%E3e";
public static void main(String... args) {
String senc = urlEncoded;
int offSet = senc.indexOf('%');
StringBuilder sb = new StringBuilder();
while (offSet > -1) {
String hex = senc.substring(offSet + 2, offSet + 4);
// hex to char, see http://stackoverflow.com/a/10101779/3080094
char c = (char)Integer.parseInt(hex, 16);
sb.append(c);
offSet = senc.indexOf('%', offSet + 1);
}
System.out.println(sb.toString());
}
}
Which produces:
<iframe marginheight="0" marginwidth="0" scrolling="no"
frameborder="0" width="540" height="304"
src="http://mp4upload.com/embed-4khqfz74ngjn.html"></iframe>

Integrating MaltParser into java code, without using a separate process

There are several resources already available for training and executing the grammatical dependency parser, MaltParser; most notably is the project's homepage: http://www.maltparser.org/userguide.html#startusing). And looking at the NLTK code that uses MaltParser, I see how I could write equivalent Java code to start up a separate child process to run MaltParser: http://nltk.org/_modules/nltk/parse/malt.html. However, what I am asking, or rather looking for, is code that clearly and cleanly shows how to integrate MaltParser as a library into a Java program.
To be specific, I want to write Java code to do the following:
Train a parsing model.
Load a trained model and parse sentences in an online fashion (i.e. stream sentences and use a MaltParser object to parse each one).
To whomever has the knowledge, patience, and willingness: please to help me answer 1 and 2!
I found a rudimentary solution to 2. I noticed that on http://www.maltparser.org/userguide.html#api it directs one to a listing of example files. I took this snippet out of one of those files:
/**
* #author Johan Hall
*/
public static void main(String[] args) {
try {
MaltParserService service = new MaltParserService();
// Inititalize the parser model 'model0' and sets the working directory to '.' and sets the logging file to 'parser.log'
service.initializeParserModel("-c model0 -m parse -w . -lfi parser.log");
// Creates an array of tokens, which contains the Swedish sentence 'Grundavdraget upphör alltså vid en taxerad inkomst på 52500 kr.'
// in the CoNLL data format.
String[] tokens = new String[11];
tokens[0] = "1\tGrundavdraget\t_\tN\tNN\tDD|SS";
tokens[1] = "2\tupphör\t_\tV\tVV\tPS|SM";
tokens[2] = "3\talltså\t_\tAB\tAB\tKS";
tokens[3] = "4\tvid\t_\tPR\tPR\t_";
tokens[4] = "5\ten\t_\tN\tEN\t_";
tokens[5] = "6\ttaxerad\t_\tP\tTP\tPA";
tokens[6] = "7\tinkomst\t_\tN\tNN\t_";
tokens[7] = "8\tpå\t_\tPR\tPR\t_";
tokens[8] = "9\t52500\t_\tR\tRO\t_";
tokens[9] = "10\tkr\t_\tN\tNN\t_";
tokens[10] = "11\t.\t_\tP\tIP\t_";
// Parses the Swedish sentence above
DependencyStructure graph = service.parse(tokens);
// Outputs the dependency graph created by MaltParser.
System.out.println(graph);
// Terminates the parser model
service.terminateParserModel();
} catch (MaltChainedException e) {
System.err.println("MaltParser exception: " + e.getMessage());
}
}

NFC with NFC-Tools, Creating NDEF Application

I am attempting to do what I would have guessed would be pretty simple, but as it turns out is not. I have an ACR122 NFC reader and a bunch of Mifare Classic and Mifare Ultralight tags, and all I want to do is read and write a mime-type and a short text string to each card from a Java application. Here's what I've got working so far:
I can connect to my reader and listen for tags
I can detect which type of tag is on the reader
On the Mifare Classic tags I can loop through all of the data on the tag (after programming the tag from my phone) and build an ascii string, but most of the data is "junk" data
I can determine whether or not there is an Application directory on the tag.
Here's my code for doing that:
Main:
public static void main(String[] args){
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals;
try{
TerminalHandler handler = new TerminalHandler();
terminals = factory.terminals().list();
CardTerminal cardTerminal = terminals.get(0);
AcsTerminal terminal = new AcsTerminal();
terminal.setCardTerminal(cardTerminal);
handler.addTerminal(terminal);
NfcAdapter adapter = new NfcAdapter(handler.getAvailableTerminal(), TerminalMode.INITIATOR);
adapter.registerTagListener(new CustomNDEFListener());
adapter.startListening();
System.in.read();
adapter.stopListening();
}
catch(IOException e){
}
catch(CardException e){
System.out.println("CardException: " + e.getMessage());
}
}
CustomNDEFListener:
public class CustomNDEFListener extends AbstractCardTool
{
#Override
public void doWithReaderWriter(MfClassicReaderWriter readerWriter)
throws IOException{
NdefMessageDecoder decoder = NdefContext.getNdefMessageDecoder();
MadKeyConfig config = MfConstants.NDEF_KEY_CONFIG;
if(readerWriter.hasApplicationDirectory()){
System.out.println("Application Directory Found!");
ApplicationDirectory directory = readerWriter.getApplicationDirectory();
}
else{
System.out.println("No Application Directory Found, creating one.");
readerWriter.createApplicationDirectory(config);
}
}
}
From here, I seem to be at a loss as for how to actually create and interact with an application. Once I can create the application and write Record objects to it, I should be able to write the data I need using the TextMimeRecord type, I just don't know how to get there. Any thoughts?
::Addendum::
Apparently there is no nfc-tools tag, and there probably should be. Would someone with enough rep be kind enough to create one and retag my question to include it?
::Second Addendum::
Also, I am willing to ditch NFC-Tools if someone can point me in the direction of a library that works for what I need, is well documented, and will run in a Windows environment.
Did you checked this library ? It is well written, how ever has poor documentation. Actually no more than JavaDoc.

Categories

Resources