Help add rules to an external file

I follow those steps:

but some error happened.
Exception in thread “main” java.lang.RuntimeException: Could not activate rules
at org.languagetool.JLanguageTool.(JLanguageTool.java:178)
at org.languagetool.JLanguageTool.(JLanguageTool.java:158)
at org.languagetool.LanguageToolTest.main(LanguageToolTest.java:10)
Caused by: java.io.IOException: Cannot load or parse input stream of ‘/org/languagetool/rules/en/grammar.xml’
at org.languagetool.rules.patterns.PatternRuleLoader.getRules(PatternRuleLoader.java:76)
at org.languagetool.Language.getPatternRules(Language.java:461)
at org.languagetool.JLanguageTool.activateDefaultPatternRules(JLanguageTool.java:321)
at org.languagetool.JLanguageTool.(JLanguageTool.java:175)
… 2 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at sun.net.ftp.impl.FtpClient.doConnect(FtpClient.java:958)
at sun.net.ftp.impl.FtpClient.tryConnect(FtpClient.java:918)
at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1013)
at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:999)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:294)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:393)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:613)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1290)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1227)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1915)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3059)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.languagetool.rules.patterns.PatternRuleLoader.getRules(PatternRuleLoader.java:73)
… 5 more

How should I do ?
Thanks.

Please post your modified grammar.xml file for debugging.

<!DOCTYPE rules [
<!ENTITY abbrevWeekdays "Mon|Mo|Tue|Tu|Wed|We|Thu|Th|Fri|Fr|Sat|Sa|Sun|Su">
<!ENTITY months "January|February|March|April|May|June|July|August|September|October|November|December">
<!ENTITY abbrevMonths "Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Sept|Oct|Nov|Dec">
<b><!ENTITY UserRules SYSTEM "file://D:/MyEclipse2015 Workspace/org.languagetool-2.8/src/org/languagetool/rules/en/user-rules.xml"></b>

]>

&UserRules;

Thanks, For my programming skills, could you tell me what’s wrong with my code (below)?
Thanks again.

<!DOCTYPE rules [
<!ENTITY abbrevWeekdays "Mon|Mo|Tue|Tu|Wed|We|Thu|Th|Fri|Fr|Sat|Sa|Sun|Su">
<!ENTITY months "January|February|March|April|May|June|July|August|September|October|November|December">
<!ENTITY abbrevMonths "Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Sept|Oct|Nov|Dec">
<!ENTITY UserRules SYSTEM "file://D:/MyEclipse2015 Workspace/org.languagetool-2.8/src/org/languagetool/rules/en/user-rules.xml">

]>

<rule>    
    &UserRules;
    </category>

This works for me:

BEFORE I add

<rule name="!Kumara">    &UserRules;</category>

In my user-rules.xml I have

<rule name="!Kumara">    

...the rules...

</category>

Thanks, and I tried, but still could not activate rules. Could you tell me more detail?

Have you checked Options/Preference to see if your rules appear and are activated?

It’s doesn’t matter, the program is running error. It must be something wrong with grammar.xml, so I want to konw what’s your change(add or del) in grammar.xml and user-rules.xml. Thanks.

Mility [via LanguageTool User Forum] wrote thus at 05:02 PM 10-04-15:

It’s doesn’t matter, the program is running error. It must be
something wrong with grammar.xml, so I want to konw what’s your
change(add or del) in grammar.xml and user-rules.xml. Thanks.

As far as I can tell, I’ve already told you everything. Other points
are as instructed in the help. You’re using a proper xml editor, I
hope. Sometimes, that can show us a minor typo that throws off the whole thing.

Anyway, you have this?

<!DOCTYPE rules [

And sth like this at the end?

<rule name="!Kumara">    &UserRules;</category>

Thanks, I have knew what’s wrong with my grammar.

HI,can you tell me how did you solve this problem?
I have the same error as yours,thx!

Rincy [via LanguageTool User Forum] wrote thus at 01:18 PM 23-11-15:

HI,can you tell me how did you solve this problem? I have the same
error with you,thx!

Please indicate all that you’ve done.

In the grammar.xml, you can follow the above Kumara do. also

<!DOCTYPE rules [

And sth like this at the end?

<rule name="!Mility">    &UserRules;</category>
In addtion, you should add
<rule name="!Mility"  type = "grammar">    
........user-rules here.....
</category>

in user-rules.xml, maybe this could help you.

In my rules-en-English.xml :

<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="../../../../../../../../../languagetool-core/src/main/resources/org/languagetool/rules/print.xsl" ?> <?xml-stylesheet type="text/css" href="../../../../../../../../../languagetool-core/src/main/resources/org/languagetool/rules/rules.css" title="Easy editing stylesheet" ?> <!DOCTYPE rules [

]>

<rules lang="en" xsi:noNamespaceSchemaLocation="../../../../../../../../../languagetool-core/src/main/resources/org/languagetool/rules/rules.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">    

        
<rule name="!Rincy" type = "grammar">    
                  <rule ...>
                   ....
                  </rule>

        </category>


    
<rule name="!Rincy">    &UserRules;</category>

OK. I thought so.

This:

<!DOCTYPE rules [

]>

should be merged with the other existing “!DOCTYPE rules”. Using your location of the XML, it should looks like this:

<!DOCTYPE rules [
<!ENTITY abbrevWeekdays "Mon|Mo|Tue|Tu|Wed|We|Thu|Th|Fri|Fr|Sat|Sa|Sun|Su">
<!ENTITY months "January|February|March|April|May|June|July|August|September|October|November|December">
<!ENTITY abbrevMonths "Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Sept|Oct|Nov|Dec">
<!ENTITY UserRules SYSTEM "file:///D:\rules-en-English.xml">

]>

Notice the last one.

Thx Kumara,follow your tips,I add the in my rules-en-English.xml file.

I open the my xml file by double clicking the languagetool.jar.
And it still reports the same error :

When I copy these rules to the grammar.xml , they can be matched. So I think the rules are right.
Is the way I open the .xml file wrong?

Rincy wrote: … in my rules-en-English.xml file.

I think that DOCTYPE must be in grammar.xml only.

I want to add external abc.xml file but I am unable to run it. It’s not responding in separate file?
How can I run external abc.xml file?
Above discussion is not helpful because no one told about the proper solution. Please guide me properly.

Thanks

This is documented at Tips and Tricks - LanguageTool Wiki.

1 Like

Hi Daniel
I already have checked that specific page, but I couldn’t find any helpful material could you please explain me with some practical example?

Thanks a bunch