Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Wednesday, April 26, 2017

OpenNLP sentence detector and Oracle JDeveloper 12c

Oracle has released its chatbots application recently and I was curious about the technology behind chatbots in general. So I explored open source natural language processing framework OpenNLP and build a simple sentence detector application using my favourite IDE Oracle JDeveloper 12c.

Input/Output:
Here is my first OpenNLP project for sentence detection, for example given a string : How are you ? This is Mike, the output should detect two sentences : How are you ? and This is Mike.
By default OpenNLP does not support Bahasa language and I tried to create sample corpora for training.

For example : Apa kabar ? saya Elva , would have output : Apa kabar ? and saya Elva

Train model for Bahasa:
OpenNLP provides command line tool for training new model. To train new Bahasa sentence detector, use following command:

$ ./opennlp SentenceDetectorTrainer -model ../id-opennlp-models/id-sent.bin -lang id -data ../id-opennlp-models/id-train.sent -encoding UTF-8

This command will generate id-sent.bin as our model file and can be used in our project:

    public static void SentenceDetectIndo() throws InvalidFormatException,
                    IOException {
            String paragraph = "Apa Kabar? Saya Elva.";
            // always start with a model, a model is learned from training data
            InputStream is = new FileInputStream("id-sent.bin");
            SentenceModel model = new SentenceModel(is);
            SentenceDetectorME sdetector = new SentenceDetectorME(model);
   
            String sentences[] = sdetector.sentDetect(paragraph);
   
            System.out.println(sentences[0]);
            System.out.println(sentences[1]);
            is.close();
    }

Output:
Apa Kabar?
Saya Elva.

Conclusion:
OpenNLP is a powerful open source natural language processing framework, easy to use and allow us to train our own model using simple command line. In this project, I successfully create a simple sentence detector application, training my own Bahasa language model and use it to detect sentences in Bahasa.

Sample project file download here (sorry about big file size 57 MB, because the project includes complete required libraries and english models)


Sunday, January 1, 2017

Using ADF View Object to display huge datasets

Issue:
In some cases, we may have huge database table with million of records or more. Querying and displaying these records may slow down your web application if it is not coded efficiently.

Solution:
Using Oracle ADF View Object component, you can tune database query easily. If you need to display only certain number of records, you can use View Object tuning configuration and set number of row to display to UI. This will increase performance by reducing number of records need to be returned from database and displayed.

Example:
In ADF Model project, double click on View Object and go to General tab. You should see Tuning option like below.



Set "Only up to row number" to display "Top-N" entries in the page and avoiding database to return all the records from database.

Often you may want to use Query Optimizer Hint FIRST_ROWS that gives a hint to the database that you want to return the first rows as quick as possible rather than trying to optimize the retrieval of all records.





Friday, December 30, 2016

Using PL/SQL in Oracle ADF Web Application

Issue:
There are many common cases where we need to build process with intensive database operations which may involve thousands or more records. Building the logic in Java or ADF model layer will cause overhead in Java memory and garbage collections.

Solution:
It is recommended to build such process in database layer and then called from ADF model layer.
With this approach, we have some benefits:
1) Database operations will be running in database servers with one db call.
2) Decouple database and application codes which will make it easier for maintenance.
3) Cleaner ADF backend codes

Example:
We can create ADF ApplicationModule class which contains method to invoke our database stored procedure.

public class AppModuleImpl extends ApplicationModuleImpl implements AppModule {

    public void callDBProc(String param1) {
        try {
            getDBTransaction().executeCommand("begin callDbProc('" + param1 + "'); end;");
        } catch (Exception sqle) {
            sqle.printStackTrace();
            throw new JboException(sqle.getMessage());
        }
    }

}

Wednesday, July 4, 2012

Shorter URL parameters for ADF Application

Yes. It is shorter than before now with new ADF version 11.1.2.2.0.

Old ADF URL parameters:
https://host/myapp/app1?_afrLoop=54603428702000&Adf-Window-Id=w0&_afrWindowMode=0&_adf.ctrl-state=8y48oltmq_3&_afrRedirect=54603481521000

New ADF 11.1.2.2.0 removes all these URL parameters except the controller state, so it becomes

https://host/myapp/app1?_adf.ctrl-state=8y48oltmq_7

I think in future release, all these internal parameters will be removed from URL and makes ADF Application prettier :)

WebLogic 11g : How to setup SSL for my website?

Okay, development is done, application deployed, but wait i need to ensure data is encrypted between users browser and my weblogic server. So how to do that?

Step 1. Generate a private keystore and private key

Example ./keytool -genkey -alias myalias -keyalg RSA -keysize 2048 -keystore mykeystore.jks

Step 2. Generate a CSR which we'll send to Certificate Authority
Example ./keytool -certreq -alias myalias -file mycertrequest.csr -keystore mykeystore.jks
Note: When generating a CSR, enter the domain of your website (i.e. www.mysite.com) in the "first- and lastname" field.

Step 3. Most of the Certificate Authority today uses Intermediate Certificate, so we need to import it to our trusted keystore
Example ./keytool -import -alias rootca -keystore mytrustkeystore.jks -trustcacerts -file intermediateCA.cer

Step 4. After receiving the certificate from Certificate Authority, import it into private key store (the initial keystore used to send the CSR)
Example ./keytool -import -alias myalias -keystore mykeystore.jks -trustcacerts -file sslcertfromca.cer

You can view the contents of keystore using below command:
./keytool -list -v -keystore mykeystore.jks -storepass mypassword

Step 5. Configure weblogic server keystore and SSL
Your Server > Configuration > Keystores
Change the Keystores to Custom Identity and Custom Trust, and then put the Keystore details as you have created before. Keystore type is JKS.

Your Server > Configuration > SSL
Put the alias that you have created before and password.

Save.

After completing above steps, restart weblogic server and don't forget to enable SSL port. Now you should be able to access your application with https.

Saturday, June 25, 2011

Introduction to Oracle J2EE Application Development Framework: Oracle ADF

If you are Java Developer and looking for a great, future proof J2EE Framework, you are at right place.
Oracle J2EE Framework has been evolved for more than 10 years. It has been improving in every release and still intensively developed by Oracle. In fact, it is the core development framework for Oracle Fusion Applications (Oracle E-Business, SOA Suite, WebCenter etc).

It started using the name Java Business Object (JBO, that's how oracle.jbo package came from), then change into Business Component for Java (BC4J), then Oracle Application Development Framework (ADF). Despite of these different naming, basic design principal is still the same with enhancement, features, bug fixes, etc.

I learned this framework since version 9i and all the experiences I had since then are still valid and it's never been a wasted effort, and i am really glad about it.

There are three main components of Oracle ADF:
1. Model
2. View
3. Controller

Simple explanation for above components:
Model is where your business data is stored (Persist).
View is where users view the Business Information based on the Model.
Controller is the connectors or links for your Views.

OK, let's start with a very basic Oracle ADF sample project. Typically, ADF Application has two projects: Model and ViewController.


Model Project contains all your business data objects. You can use different technology for this. Currently it supports ADF Business Component (XML of your database tables), Plain XML, Toplink, Text File, etc.

ViewController Project contains all your Web Application pages and ADF Controller XML files.


In above screenshot, i'm using ADF BC (That's it AppModule, Emp, EmpView are my Business Components which are built using ADF BC) in Model Project and Facelets (Emp.jsf) with ADF Controller (adfc-config.xml) in ViewController project. I hope with this very brief explanation of Oracle ADF could help you to understand what is Oracle ADF and its components.

Want to see the demo? check out this link Oracle ADF demo

Cheers!

Wednesday, May 18, 2011

So when to use Active Data Guard or Golden Gate?

On my previous post, I posted some differences between Active Data Guard and Golden Gate. But some people may find it more confusing and ask when should I use Active Data Guard? or Golden Gate?

So let me try to summarize it here:

Use Active Data Guard for:
Disaster Recovery, Data Protection/HA (Oracle environment)

Use Golden Gate for:
Information Distribution, Data Integration, Cross-platform migrations (For ex. SQL Server to Oracle)


They can also complements each other.
ADG provides read-only replica for standby database, and GG capturing standby archive logs then replicating it to 'n' different target systems.